From e386254e7b4ea6afd013c2759d675d6d13c1f568 Mon Sep 17 00:00:00 2001 From: Remi Rousselet Date: Fri, 24 Jun 2022 16:00:37 +0200 Subject: [PATCH 01/16] feat: Add JsonSerializable(createJsonMeta) --- .../lib/src/json_serializable.dart | 8 ++++++ json_serializable/lib/src/encoder_helper.dart | 20 +++++++++++++ .../lib/src/generator_helper.dart | 4 +++ .../lib/src/type_helpers/config_types.dart | 6 ++++ json_serializable/lib/src/utils.dart | 2 ++ json_serializable/test/config_test.dart | 1 + .../test/integration/integration_test.dart | 11 ++++++++ .../test/integration/json_meta_example.dart | 28 +++++++++++++++++++ .../test/integration/json_meta_example.g.dart | 24 ++++++++++++++++ json_serializable/test/shared_config.dart | 1 + .../test/test_sources/test_sources.dart | 1 + 11 files changed, 106 insertions(+) create mode 100644 json_serializable/test/integration/json_meta_example.dart create mode 100644 json_serializable/test/integration/json_meta_example.g.dart diff --git a/json_annotation/lib/src/json_serializable.dart b/json_annotation/lib/src/json_serializable.dart index 34fe2abb6..13be3af4a 100644 --- a/json_annotation/lib/src/json_serializable.dart +++ b/json_annotation/lib/src/json_serializable.dart @@ -64,6 +64,13 @@ class JsonSerializable { /// This setting has no effect if [createFactory] is `false`. final String? constructor; + /// 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? createJsonMeta; + /// If `true` (the default), a private, static `_$ExampleFromJson` method /// is created in the generated part file. /// @@ -231,6 +238,7 @@ class JsonSerializable { this.anyMap, this.checked, this.constructor, + this.createJsonMeta, this.createFactory, this.createToJson, this.disallowUnrecognizedKeys, diff --git a/json_serializable/lib/src/encoder_helper.dart b/json_serializable/lib/src/encoder_helper.dart index fd963329d..71b7a2a84 100644 --- a/json_serializable/lib/src/encoder_helper.dart +++ b/json_serializable/lib/src/encoder_helper.dart @@ -16,6 +16,26 @@ 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 createJsonMeta(Set accessibleFieldSet) { + assert(config.createJsonMeta); + + final buffer = + StringBuffer('const _\$${element.name}JsonMeta = {'); + + for (final field in accessibleFieldSet) { + buffer.writeln( + '${escapeDartString(field.name)}: ' + '${escapeDartString(nameAccess(field))},', + ); + } + + buffer.write('};'); + + return buffer.toString(); + } + Iterable createToJson(Set 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..ecf8bb22d 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.createJsonMeta) { + yield createJsonMeta(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..34357a6cc 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 createJsonMeta; 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.createJsonMeta, 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, + createJsonMeta: + config.createJsonMeta ?? ClassConfig.defaults.createJsonMeta, createFactory: config.createFactory ?? ClassConfig.defaults.createFactory, createToJson: config.createToJson ?? ClassConfig.defaults.createToJson, @@ -101,6 +105,7 @@ class ClassConfig { constructor: '', createFactory: true, createToJson: true, + createJsonMeta: false, disallowUnrecognizedKeys: false, explicitToJson: false, fieldRename: FieldRename.none, @@ -115,6 +120,7 @@ class ClassConfig { constructor: constructor, createFactory: createFactory, createToJson: createToJson, + createJsonMeta: createJsonMeta, ignoreUnannotated: ignoreUnannotated, explicitToJson: explicitToJson, includeIfNull: includeIfNull, diff --git a/json_serializable/lib/src/utils.dart b/json_serializable/lib/src/utils.dart index 470627491..1bcc645c2 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?, + createJsonMeta: reader.read('createJsonMeta').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, + createJsonMeta: annotation.createJsonMeta ?? config.createJsonMeta, disallowUnrecognizedKeys: annotation.disallowUnrecognizedKeys ?? config.disallowUnrecognizedKeys, explicitToJson: annotation.explicitToJson ?? config.explicitToJson, diff --git a/json_serializable/test/config_test.dart b/json_serializable/test/config_test.dart index 811567b81..f90f14256 100644 --- a/json_serializable/test/config_test.dart +++ b/json_serializable/test/config_test.dart @@ -152,6 +152,7 @@ const _invalidConfig = { 'checked': 42, 'constructor': 42, 'create_factory': 42, + 'create_json_meta': 42, 'create_to_json': 42, 'disallow_unrecognized_keys': 42, 'explicit_to_json': 42, diff --git a/json_serializable/test/integration/integration_test.dart b/json_serializable/test/integration/integration_test.dart index 22dc186aa..5be29f21d 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 'json_enum_example.dart'; +import 'json_meta_example.dart'; import 'json_test_common.dart' show Category, Platform, StatusCode; import 'json_test_example.dart'; @@ -322,4 +323,14 @@ void main() { isNull, ); }); + + test(r'_$ModelJsonMeta', () { + expect( + modelMeta, + { + 'firstName': 'first-name', + 'lastName': 'LAST_NAME', + }, + ); + }); } diff --git a/json_serializable/test/integration/json_meta_example.dart b/json_serializable/test/integration/json_meta_example.dart new file mode 100644 index 000000000..3006e0ea7 --- /dev/null +++ b/json_serializable/test/integration/json_meta_example.dart @@ -0,0 +1,28 @@ +import 'package:json_annotation/json_annotation.dart'; + +part 'json_meta_example.g.dart'; + +@JsonSerializable(createJsonMeta: true, fieldRename: FieldRename.kebab) +class Model { + Model({ + required this.firstName, + required this.lastName, + this.ignoredName, + }); + + factory Model.fromJson(Map 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 toJson() => _$ModelToJson(this); +} + +const modelMeta = _$ModelJsonMeta; diff --git a/json_serializable/test/integration/json_meta_example.g.dart b/json_serializable/test/integration/json_meta_example.g.dart new file mode 100644 index 000000000..5ab3816ca --- /dev/null +++ b/json_serializable/test/integration/json_meta_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 + +part of 'json_meta_example.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +Model _$ModelFromJson(Map json) => Model( + firstName: json['first-name'] as String, + lastName: json['LAST_NAME'] as String, + ); + +const _$ModelJsonMeta = { + 'firstName': 'first-name', + 'lastName': 'LAST_NAME', +}; + +Map _$ModelToJson(Model instance) => { + '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 8ee8ca585..504e1cd41 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, + createJsonMeta: 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..faf7b9e82 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, + createJsonMeta: false, disallowUnrecognizedKeys: false, explicitToJson: false, fieldRename: FieldRename.none, From dc749c123b5a85b79bd45db3187b699a05cec578 Mon Sep 17 00:00:00 2001 From: Remi Rousselet Date: Fri, 24 Jun 2022 16:06:25 +0200 Subject: [PATCH 02/16] Fix config_test --- json_serializable/test/config_test.dart | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/json_serializable/test/config_test.dart b/json_serializable/test/config_test.dart index f90f14256..c39bab146 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"; From 105ab22692638c76e385e7ed4b03b4cf9d74f627 Mon Sep 17 00:00:00 2001 From: Remi Rousselet Date: Fri, 24 Jun 2022 17:04:54 +0200 Subject: [PATCH 03/16] update json_annotation --- .../lib/src/json_serializable.dart | 1 + .../lib/src/json_serializable.g.dart | 46 ++++--------------- 2 files changed, 9 insertions(+), 38 deletions(-) diff --git a/json_annotation/lib/src/json_serializable.dart b/json_annotation/lib/src/json_serializable.dart index 13be3af4a..3ece02e6b 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'; diff --git a/json_annotation/lib/src/json_serializable.g.dart b/json_annotation/lib/src/json_serializable.g.dart index 65d452093..5589116af 100644 --- a/json_annotation/lib/src/json_serializable.g.dart +++ b/json_annotation/lib/src/json_serializable.g.dart @@ -1,5 +1,7 @@ // GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal + part of 'json_serializable.dart'; // ************************************************************************** @@ -17,6 +19,7 @@ JsonSerializable _$JsonSerializableFromJson(Map json) => 'any_map', 'checked', 'constructor', + 'create_json_meta', 'create_factory', 'create_to_json', 'disallow_unrecognized_keys', @@ -31,6 +34,8 @@ JsonSerializable _$JsonSerializableFromJson(Map json) => anyMap: $checkedConvert('any_map', (v) => v as bool?), checked: $checkedConvert('checked', (v) => v as bool?), constructor: $checkedConvert('constructor', (v) => v as String?), + createJsonMeta: + $checkedConvert('create_json_meta', (v) => v as bool?), createFactory: $checkedConvert('create_factory', (v) => v as bool?), createToJson: $checkedConvert('create_to_json', (v) => v as bool?), disallowUnrecognizedKeys: @@ -38,7 +43,7 @@ JsonSerializable _$JsonSerializableFromJson(Map 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 +54,7 @@ JsonSerializable _$JsonSerializableFromJson(Map json) => }, fieldKeyMap: const { 'anyMap': 'any_map', + 'createJsonMeta': 'create_json_meta', 'createFactory': 'create_factory', 'createToJson': 'create_to_json', 'disallowUnrecognizedKeys': 'disallow_unrecognized_keys', @@ -65,6 +71,7 @@ Map _$JsonSerializableToJson(JsonSerializable instance) => 'any_map': instance.anyMap, 'checked': instance.checked, 'constructor': instance.constructor, + 'create_json_meta': instance.createJsonMeta, 'create_factory': instance.createFactory, 'create_to_json': instance.createToJson, 'disallow_unrecognized_keys': instance.disallowUnrecognizedKeys, @@ -75,43 +82,6 @@ Map _$JsonSerializableToJson(JsonSerializable instance) => 'include_if_null': instance.includeIfNull, }; -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 _$FieldRenameEnumMap = { FieldRename.none: 'none', FieldRename.kebab: 'kebab', From 3f9bbadb240462177898ec044dd3d7f3ad9324e6 Mon Sep 17 00:00:00 2001 From: Remi Rousselet Date: Mon, 27 Jun 2022 13:05:45 +0200 Subject: [PATCH 04/16] createJsonMeta -> createFieldMap --- json_annotation/lib/src/json_serializable.dart | 4 ++-- json_annotation/lib/src/json_serializable.g.dart | 10 +++++----- json_serializable/lib/src/encoder_helper.dart | 6 +++--- json_serializable/lib/src/generator_helper.dart | 4 ++-- .../lib/src/type_helpers/config_types.dart | 12 ++++++------ json_serializable/lib/src/utils.dart | 4 ++-- json_serializable/test/config_test.dart | 2 +- .../test/integration/json_meta_example.dart | 4 ++-- .../test/integration/json_meta_example.g.dart | 2 +- json_serializable/test/shared_config.dart | 2 +- .../test/test_sources/test_sources.dart | 2 +- 11 files changed, 26 insertions(+), 26 deletions(-) diff --git a/json_annotation/lib/src/json_serializable.dart b/json_annotation/lib/src/json_serializable.dart index 3ece02e6b..fed8d209d 100644 --- a/json_annotation/lib/src/json_serializable.dart +++ b/json_annotation/lib/src/json_serializable.dart @@ -70,7 +70,7 @@ class JsonSerializable { /// /// This constant can be used by other code-generators to support features /// such as [fieldRename]. - final bool? createJsonMeta; + final bool? createFieldMap; /// If `true` (the default), a private, static `_$ExampleFromJson` method /// is created in the generated part file. @@ -239,7 +239,7 @@ class JsonSerializable { this.anyMap, this.checked, this.constructor, - this.createJsonMeta, + 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 5589116af..81baef1e9 100644 --- a/json_annotation/lib/src/json_serializable.g.dart +++ b/json_annotation/lib/src/json_serializable.g.dart @@ -19,7 +19,7 @@ JsonSerializable _$JsonSerializableFromJson(Map json) => 'any_map', 'checked', 'constructor', - 'create_json_meta', + 'create_field_map', 'create_factory', 'create_to_json', 'disallow_unrecognized_keys', @@ -34,8 +34,8 @@ JsonSerializable _$JsonSerializableFromJson(Map json) => anyMap: $checkedConvert('any_map', (v) => v as bool?), checked: $checkedConvert('checked', (v) => v as bool?), constructor: $checkedConvert('constructor', (v) => v as String?), - createJsonMeta: - $checkedConvert('create_json_meta', (v) => v as bool?), + 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: @@ -54,7 +54,7 @@ JsonSerializable _$JsonSerializableFromJson(Map json) => }, fieldKeyMap: const { 'anyMap': 'any_map', - 'createJsonMeta': 'create_json_meta', + 'createFieldMap': 'create_field_map', 'createFactory': 'create_factory', 'createToJson': 'create_to_json', 'disallowUnrecognizedKeys': 'disallow_unrecognized_keys', @@ -71,7 +71,7 @@ Map _$JsonSerializableToJson(JsonSerializable instance) => 'any_map': instance.anyMap, 'checked': instance.checked, 'constructor': instance.constructor, - 'create_json_meta': instance.createJsonMeta, + 'create_field_map': instance.createFieldMap, 'create_factory': instance.createFactory, 'create_to_json': instance.createToJson, 'disallow_unrecognized_keys': instance.disallowUnrecognizedKeys, diff --git a/json_serializable/lib/src/encoder_helper.dart b/json_serializable/lib/src/encoder_helper.dart index 71b7a2a84..b687f2c8b 100644 --- a/json_serializable/lib/src/encoder_helper.dart +++ b/json_serializable/lib/src/encoder_helper.dart @@ -18,11 +18,11 @@ abstract class EncodeHelper implements HelperCore { /// Generates an object containing metadatas related to the encoding, /// destined to be used by other code-generators. - String createJsonMeta(Set accessibleFieldSet) { - assert(config.createJsonMeta); + String createFieldMap(Set accessibleFieldSet) { + assert(config.createFieldMap); final buffer = - StringBuffer('const _\$${element.name}JsonMeta = {'); + StringBuffer('const _\$${element.name}FieldMap = {'); for (final field in accessibleFieldSet) { buffer.writeln( diff --git a/json_serializable/lib/src/generator_helper.dart b/json_serializable/lib/src/generator_helper.dart index ecf8bb22d..f4016292a 100644 --- a/json_serializable/lib/src/generator_helper.dart +++ b/json_serializable/lib/src/generator_helper.dart @@ -108,8 +108,8 @@ class GeneratorHelper extends HelperCore with EncodeHelper, DecodeHelper { }, ); - if (config.createJsonMeta) { - yield createJsonMeta(accessibleFieldSet); + if (config.createFieldMap) { + yield createFieldMap(accessibleFieldSet); } if (config.createToJson) { diff --git a/json_serializable/lib/src/type_helpers/config_types.dart b/json_serializable/lib/src/type_helpers/config_types.dart index 34357a6cc..d352d16af 100644 --- a/json_serializable/lib/src/type_helpers/config_types.dart +++ b/json_serializable/lib/src/type_helpers/config_types.dart @@ -45,7 +45,7 @@ class ClassConfig { final String constructor; final bool createFactory; final bool createToJson; - final bool createJsonMeta; + final bool createFieldMap; final bool disallowUnrecognizedKeys; final bool explicitToJson; final FieldRename fieldRename; @@ -61,7 +61,7 @@ class ClassConfig { required this.constructor, required this.createFactory, required this.createToJson, - required this.createJsonMeta, + required this.createFieldMap, required this.disallowUnrecognizedKeys, required this.explicitToJson, required this.fieldRename, @@ -78,8 +78,8 @@ class ClassConfig { checked: config.checked ?? ClassConfig.defaults.checked, anyMap: config.anyMap ?? ClassConfig.defaults.anyMap, constructor: config.constructor ?? ClassConfig.defaults.constructor, - createJsonMeta: - config.createJsonMeta ?? ClassConfig.defaults.createJsonMeta, + createFieldMap: + config.createFieldMap ?? ClassConfig.defaults.createFieldMap, createFactory: config.createFactory ?? ClassConfig.defaults.createFactory, createToJson: config.createToJson ?? ClassConfig.defaults.createToJson, @@ -105,7 +105,7 @@ class ClassConfig { constructor: '', createFactory: true, createToJson: true, - createJsonMeta: false, + createFieldMap: false, disallowUnrecognizedKeys: false, explicitToJson: false, fieldRename: FieldRename.none, @@ -120,7 +120,7 @@ class ClassConfig { constructor: constructor, createFactory: createFactory, createToJson: createToJson, - createJsonMeta: createJsonMeta, + 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 1bcc645c2..38dbba64b 100644 --- a/json_serializable/lib/src/utils.dart +++ b/json_serializable/lib/src/utils.dart @@ -56,7 +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?, - createJsonMeta: reader.read('createJsonMeta').literalValue as bool?, + createFieldMap: reader.read('createFieldMap').literalValue as bool?, disallowUnrecognizedKeys: reader.read('disallowUnrecognizedKeys').literalValue as bool?, explicitToJson: reader.read('explicitToJson').literalValue as bool?, @@ -102,7 +102,7 @@ ClassConfig mergeConfig( constructor: constructor, createFactory: annotation.createFactory ?? config.createFactory, createToJson: annotation.createToJson ?? config.createToJson, - createJsonMeta: annotation.createJsonMeta ?? config.createJsonMeta, + createFieldMap: annotation.createFieldMap ?? config.createFieldMap, disallowUnrecognizedKeys: annotation.disallowUnrecognizedKeys ?? config.disallowUnrecognizedKeys, explicitToJson: annotation.explicitToJson ?? config.explicitToJson, diff --git a/json_serializable/test/config_test.dart b/json_serializable/test/config_test.dart index c39bab146..d98942607 100644 --- a/json_serializable/test/config_test.dart +++ b/json_serializable/test/config_test.dart @@ -156,7 +156,7 @@ const _invalidConfig = { 'checked': 42, 'constructor': 42, 'create_factory': 42, - 'create_json_meta': 42, + 'create_field_map': 42, 'create_to_json': 42, 'disallow_unrecognized_keys': 42, 'explicit_to_json': 42, diff --git a/json_serializable/test/integration/json_meta_example.dart b/json_serializable/test/integration/json_meta_example.dart index 3006e0ea7..cfabac0c2 100644 --- a/json_serializable/test/integration/json_meta_example.dart +++ b/json_serializable/test/integration/json_meta_example.dart @@ -2,7 +2,7 @@ import 'package:json_annotation/json_annotation.dart'; part 'json_meta_example.g.dart'; -@JsonSerializable(createJsonMeta: true, fieldRename: FieldRename.kebab) +@JsonSerializable(createFieldMap: true, fieldRename: FieldRename.kebab) class Model { Model({ required this.firstName, @@ -25,4 +25,4 @@ class Model { Map toJson() => _$ModelToJson(this); } -const modelMeta = _$ModelJsonMeta; +const modelMeta = _$ModelFieldMap; diff --git a/json_serializable/test/integration/json_meta_example.g.dart b/json_serializable/test/integration/json_meta_example.g.dart index 5ab3816ca..1ef78d543 100644 --- a/json_serializable/test/integration/json_meta_example.g.dart +++ b/json_serializable/test/integration/json_meta_example.g.dart @@ -13,7 +13,7 @@ Model _$ModelFromJson(Map json) => Model( lastName: json['LAST_NAME'] as String, ); -const _$ModelJsonMeta = { +const _$ModelFieldMap = { 'firstName': 'first-name', 'lastName': 'LAST_NAME', }; diff --git a/json_serializable/test/shared_config.dart b/json_serializable/test/shared_config.dart index 504e1cd41..e387488e9 100644 --- a/json_serializable/test/shared_config.dart +++ b/json_serializable/test/shared_config.dart @@ -19,7 +19,7 @@ final generatorConfigNonDefaultJson = constructor: 'something', createFactory: false, createToJson: false, - createJsonMeta: true, + 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 faf7b9e82..3d3c3b368 100644 --- a/json_serializable/test/test_sources/test_sources.dart +++ b/json_serializable/test/test_sources/test_sources.dart @@ -15,7 +15,7 @@ class ConfigurationImplicitDefaults { constructor: '', createFactory: true, createToJson: true, - createJsonMeta: false, + createFieldMap: false, disallowUnrecognizedKeys: false, explicitToJson: false, fieldRename: FieldRename.none, From 604faa0f135367133b7194a0c7d68d8e3802d6a8 Mon Sep 17 00:00:00 2001 From: Remi Rousselet Date: Mon, 27 Jun 2022 13:13:19 +0200 Subject: [PATCH 05/16] Test private fieldMap --- json_serializable/lib/src/encoder_helper.dart | 5 +++-- ..._meta_example.dart => field_map_example.dart} | 15 +++++++++++++-- ...a_example.g.dart => field_map_example.g.dart} | 16 +++++++++++++++- .../test/integration/integration_test.dart | 14 +++++++++++--- 4 files changed, 42 insertions(+), 8 deletions(-) rename json_serializable/test/integration/{json_meta_example.dart => field_map_example.dart} (62%) rename json_serializable/test/integration/{json_meta_example.g.dart => field_map_example.g.dart} (65%) diff --git a/json_serializable/lib/src/encoder_helper.dart b/json_serializable/lib/src/encoder_helper.dart index b687f2c8b..9bb045852 100644 --- a/json_serializable/lib/src/encoder_helper.dart +++ b/json_serializable/lib/src/encoder_helper.dart @@ -21,8 +21,9 @@ abstract class EncodeHelper implements HelperCore { String createFieldMap(Set accessibleFieldSet) { assert(config.createFieldMap); - final buffer = - StringBuffer('const _\$${element.name}FieldMap = {'); + final buffer = StringBuffer( + 'const _\$${element.name.nonPrivate}FieldMap = {', + ); for (final field in accessibleFieldSet) { buffer.writeln( diff --git a/json_serializable/test/integration/json_meta_example.dart b/json_serializable/test/integration/field_map_example.dart similarity index 62% rename from json_serializable/test/integration/json_meta_example.dart rename to json_serializable/test/integration/field_map_example.dart index cfabac0c2..c200096cd 100644 --- a/json_serializable/test/integration/json_meta_example.dart +++ b/json_serializable/test/integration/field_map_example.dart @@ -1,6 +1,6 @@ import 'package:json_annotation/json_annotation.dart'; -part 'json_meta_example.g.dart'; +part 'field_map_example.g.dart'; @JsonSerializable(createFieldMap: true, fieldRename: FieldRename.kebab) class Model { @@ -25,4 +25,15 @@ class Model { Map toJson() => _$ModelToJson(this); } -const modelMeta = _$ModelFieldMap; +const modelFieldMap = _$ModelFieldMap; + +@JsonSerializable(createFieldMap: true, fieldRename: FieldRename.kebab) +class _PrivateModel { + _PrivateModel(this.fullName); + + final String fullName; + + Map toJson() => _$PrivateModelToJson(this); +} + +const privateModelFieldMap = _$PrivateModelFieldMap; diff --git a/json_serializable/test/integration/json_meta_example.g.dart b/json_serializable/test/integration/field_map_example.g.dart similarity index 65% rename from json_serializable/test/integration/json_meta_example.g.dart rename to json_serializable/test/integration/field_map_example.g.dart index 1ef78d543..19ddec24c 100644 --- a/json_serializable/test/integration/json_meta_example.g.dart +++ b/json_serializable/test/integration/field_map_example.g.dart @@ -2,7 +2,7 @@ // ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal -part of 'json_meta_example.dart'; +part of 'field_map_example.dart'; // ************************************************************************** // JsonSerializableGenerator @@ -22,3 +22,17 @@ Map _$ModelToJson(Model instance) => { 'first-name': instance.firstName, 'LAST_NAME': instance.lastName, }; + +_PrivateModel _$PrivateModelFromJson(Map json) => + _PrivateModel( + json['full-name'] as String, + ); + +const _$PrivateModelFieldMap = { + 'fullName': 'full-name', +}; + +Map _$PrivateModelToJson(_PrivateModel instance) => + { + 'full-name': instance.fullName, + }; diff --git a/json_serializable/test/integration/integration_test.dart b/json_serializable/test/integration/integration_test.dart index 5be29f21d..dd9289425 100644 --- a/json_serializable/test/integration/integration_test.dart +++ b/json_serializable/test/integration/integration_test.dart @@ -7,7 +7,7 @@ import 'package:test/test.dart'; import '../test_utils.dart'; import 'json_enum_example.dart'; -import 'json_meta_example.dart'; +import 'field_map_example.dart'; import 'json_test_common.dart' show Category, Platform, StatusCode; import 'json_test_example.dart'; @@ -324,13 +324,21 @@ void main() { ); }); - test(r'_$ModelJsonMeta', () { + test(r'_$ModelFieldMap', () { expect( - modelMeta, + modelFieldMap, { 'firstName': 'first-name', 'lastName': 'LAST_NAME', }, ); }); + + test(r'Generates _$PrivateModelFieldMap instead of __$PrivateModelFieldMap', + () { + expect( + privateModelFieldMap, + {'fullName': 'full-name'}, + ); + }); } From d0bda6a70be1aa6632916607398dc620553fe29f Mon Sep 17 00:00:00 2001 From: Remi Rousselet Date: Mon, 27 Jun 2022 13:56:39 +0200 Subject: [PATCH 06/16] Fix analyzer --- json_serializable/test/integration/field_map_example.dart | 6 +++++- json_serializable/test/integration/field_map_example.g.dart | 5 ----- json_serializable/test/integration/integration_test.dart | 2 +- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/json_serializable/test/integration/field_map_example.dart b/json_serializable/test/integration/field_map_example.dart index c200096cd..9d06a15ef 100644 --- a/json_serializable/test/integration/field_map_example.dart +++ b/json_serializable/test/integration/field_map_example.dart @@ -27,7 +27,11 @@ class Model { const modelFieldMap = _$ModelFieldMap; -@JsonSerializable(createFieldMap: true, fieldRename: FieldRename.kebab) +@JsonSerializable( + createFieldMap: true, + fieldRename: FieldRename.kebab, + createFactory: false, +) class _PrivateModel { _PrivateModel(this.fullName); diff --git a/json_serializable/test/integration/field_map_example.g.dart b/json_serializable/test/integration/field_map_example.g.dart index 19ddec24c..5c50eadc3 100644 --- a/json_serializable/test/integration/field_map_example.g.dart +++ b/json_serializable/test/integration/field_map_example.g.dart @@ -23,11 +23,6 @@ Map _$ModelToJson(Model instance) => { 'LAST_NAME': instance.lastName, }; -_PrivateModel _$PrivateModelFromJson(Map json) => - _PrivateModel( - json['full-name'] as String, - ); - const _$PrivateModelFieldMap = { 'fullName': 'full-name', }; diff --git a/json_serializable/test/integration/integration_test.dart b/json_serializable/test/integration/integration_test.dart index dd9289425..e0a47a87b 100644 --- a/json_serializable/test/integration/integration_test.dart +++ b/json_serializable/test/integration/integration_test.dart @@ -6,8 +6,8 @@ import 'package:json_annotation/json_annotation.dart'; import 'package:test/test.dart'; import '../test_utils.dart'; -import 'json_enum_example.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'; From 108ab461ff89a49d7d3efedd0cc34ddf96332ea0 Mon Sep 17 00:00:00 2001 From: Remi Rousselet Date: Mon, 27 Jun 2022 14:09:17 +0200 Subject: [PATCH 07/16] Fix some tests --- json_serializable/README.md | 1 + json_serializable/test/config_test.dart | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/json_serializable/README.md b/json_serializable/README.md index ffdb481f7..72b2e9b7d 100644 --- a/json_serializable/README.md +++ b/json_serializable/README.md @@ -178,6 +178,7 @@ targets: any_map: false checked: false constructor: "" + create_field_map: false create_factory: true create_to_json: true disallow_unrecognized_keys: false diff --git a/json_serializable/test/config_test.dart b/json_serializable/test/config_test.dart index d98942607..7517e98db 100644 --- a/json_serializable/test/config_test.dart +++ b/json_serializable/test/config_test.dart @@ -155,8 +155,8 @@ const _invalidConfig = { 'any_map': 42, 'checked': 42, 'constructor': 42, - 'create_factory': 42, 'create_field_map': 42, + 'create_factory': 42, 'create_to_json': 42, 'disallow_unrecognized_keys': 42, 'explicit_to_json': 42, From 4b76cf89d9eb5f2243d9e6786d164942097b550d Mon Sep 17 00:00:00 2001 From: Remi Rousselet Date: Mon, 27 Jun 2022 14:14:04 +0200 Subject: [PATCH 08/16] Sort fieldMap field --- json_annotation/lib/src/json_serializable.g.dart | 6 +++--- json_serializable/test/config_test.dart | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/json_annotation/lib/src/json_serializable.g.dart b/json_annotation/lib/src/json_serializable.g.dart index 81baef1e9..06c25e715 100644 --- a/json_annotation/lib/src/json_serializable.g.dart +++ b/json_annotation/lib/src/json_serializable.g.dart @@ -19,8 +19,8 @@ JsonSerializable _$JsonSerializableFromJson(Map json) => 'any_map', 'checked', 'constructor', - 'create_field_map', 'create_factory', + 'create_field_map', 'create_to_json', 'disallow_unrecognized_keys', 'explicit_to_json', @@ -54,8 +54,8 @@ JsonSerializable _$JsonSerializableFromJson(Map json) => }, fieldKeyMap: const { 'anyMap': 'any_map', - 'createFieldMap': 'create_field_map', 'createFactory': 'create_factory', + 'createFieldMap': 'create_field_map', 'createToJson': 'create_to_json', 'disallowUnrecognizedKeys': 'disallow_unrecognized_keys', 'explicitToJson': 'explicit_to_json', @@ -71,8 +71,8 @@ Map _$JsonSerializableToJson(JsonSerializable instance) => 'any_map': instance.anyMap, 'checked': instance.checked, 'constructor': instance.constructor, - 'create_field_map': instance.createFieldMap, 'create_factory': instance.createFactory, + 'create_field_map': instance.createFieldMap, 'create_to_json': instance.createToJson, 'disallow_unrecognized_keys': instance.disallowUnrecognizedKeys, 'explicit_to_json': instance.explicitToJson, diff --git a/json_serializable/test/config_test.dart b/json_serializable/test/config_test.dart index 7517e98db..d98942607 100644 --- a/json_serializable/test/config_test.dart +++ b/json_serializable/test/config_test.dart @@ -155,8 +155,8 @@ const _invalidConfig = { 'any_map': 42, 'checked': 42, 'constructor': 42, - 'create_field_map': 42, 'create_factory': 42, + 'create_field_map': 42, 'create_to_json': 42, 'disallow_unrecognized_keys': 42, 'explicit_to_json': 42, From 5d00aad3b3192428ec2cd8e2270ad32b17387d7d Mon Sep 17 00:00:00 2001 From: Remi Rousselet Date: Mon, 27 Jun 2022 14:20:30 +0200 Subject: [PATCH 09/16] re-generate jsonserializable.g.dart --- json_annotation/lib/src/json_serializable.g.dart | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/json_annotation/lib/src/json_serializable.g.dart b/json_annotation/lib/src/json_serializable.g.dart index 06c25e715..81baef1e9 100644 --- a/json_annotation/lib/src/json_serializable.g.dart +++ b/json_annotation/lib/src/json_serializable.g.dart @@ -19,8 +19,8 @@ JsonSerializable _$JsonSerializableFromJson(Map json) => 'any_map', 'checked', 'constructor', - 'create_factory', 'create_field_map', + 'create_factory', 'create_to_json', 'disallow_unrecognized_keys', 'explicit_to_json', @@ -54,8 +54,8 @@ JsonSerializable _$JsonSerializableFromJson(Map json) => }, fieldKeyMap: const { 'anyMap': 'any_map', - 'createFactory': 'create_factory', 'createFieldMap': 'create_field_map', + 'createFactory': 'create_factory', 'createToJson': 'create_to_json', 'disallowUnrecognizedKeys': 'disallow_unrecognized_keys', 'explicitToJson': 'explicit_to_json', @@ -71,8 +71,8 @@ Map _$JsonSerializableToJson(JsonSerializable instance) => 'any_map': instance.anyMap, 'checked': instance.checked, 'constructor': instance.constructor, - 'create_factory': instance.createFactory, 'create_field_map': instance.createFieldMap, + 'create_factory': instance.createFactory, 'create_to_json': instance.createToJson, 'disallow_unrecognized_keys': instance.disallowUnrecognizedKeys, 'explicit_to_json': instance.explicitToJson, From 06c1640d98e5cbddca331cb1150b2d28147a28d9 Mon Sep 17 00:00:00 2001 From: Remi Rousselet Date: Mon, 27 Jun 2022 14:32:20 +0200 Subject: [PATCH 10/16] Sort fields --- json_annotation/lib/src/json_serializable.dart | 14 +++++++------- json_annotation/lib/src/json_serializable.g.dart | 6 ++---- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/json_annotation/lib/src/json_serializable.dart b/json_annotation/lib/src/json_serializable.dart index fed8d209d..17437f349 100644 --- a/json_annotation/lib/src/json_serializable.dart +++ b/json_annotation/lib/src/json_serializable.dart @@ -65,13 +65,6 @@ class JsonSerializable { /// This setting has no effect if [createFactory] is `false`. final String? constructor; - /// 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 private, static `_$ExampleFromJson` method /// is created in the generated part file. /// @@ -87,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. /// diff --git a/json_annotation/lib/src/json_serializable.g.dart b/json_annotation/lib/src/json_serializable.g.dart index 81baef1e9..34ecbe5b0 100644 --- a/json_annotation/lib/src/json_serializable.g.dart +++ b/json_annotation/lib/src/json_serializable.g.dart @@ -1,7 +1,5 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: lines_longer_than_80_chars, text_direction_code_point_in_literal - part of 'json_serializable.dart'; // ************************************************************************** @@ -19,8 +17,8 @@ JsonSerializable _$JsonSerializableFromJson(Map json) => 'any_map', 'checked', 'constructor', - 'create_field_map', 'create_factory', + 'create_field_map', 'create_to_json', 'disallow_unrecognized_keys', 'explicit_to_json', @@ -71,8 +69,8 @@ Map _$JsonSerializableToJson(JsonSerializable instance) => 'any_map': instance.anyMap, 'checked': instance.checked, 'constructor': instance.constructor, - 'create_field_map': instance.createFieldMap, 'create_factory': instance.createFactory, + 'create_field_map': instance.createFieldMap, 'create_to_json': instance.createToJson, 'disallow_unrecognized_keys': instance.disallowUnrecognizedKeys, 'explicit_to_json': instance.explicitToJson, From eda3fc72f535d35c31e24a26eaa9f854a7b9efec Mon Sep 17 00:00:00 2001 From: Remi Rousselet Date: Mon, 27 Jun 2022 14:45:52 +0200 Subject: [PATCH 11/16] Update generated files --- json_serializable/README.md | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/json_serializable/README.md b/json_serializable/README.md index 72b2e9b7d..3694c32dd 100644 --- a/json_serializable/README.md +++ b/json_serializable/README.md @@ -178,7 +178,6 @@ targets: any_map: false checked: false constructor: "" - create_field_map: false create_factory: true create_to_json: true disallow_unrecognized_keys: false @@ -200,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.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.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 From d3aeb2dca865f3948a0cd73c84b7e882cdc5fff7 Mon Sep 17 00:00:00 2001 From: Remi Rousselet Date: Mon, 27 Jun 2022 15:03:20 +0200 Subject: [PATCH 12/16] add create_field_map to readme --- json_serializable/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/json_serializable/README.md b/json_serializable/README.md index 3694c32dd..9a3083e3d 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 From 6006a3e5ce19890ece1f77d7e0602054391ebd91 Mon Sep 17 00:00:00 2001 From: Remi Rousselet Date: Mon, 27 Jun 2022 15:03:58 +0200 Subject: [PATCH 13/16] Updaye changelog/version --- json_annotation/CHANGELOG.md | 2 ++ json_serializable/CHANGELOG.md | 6 ++++++ 2 files changed, 8 insertions(+) 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: [])` ([#1072](https://github.com/google/json_serializable.dart/issues/1072)) diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index ba3e21bc9..d07cd7203 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` on properties From 4a0a053b709713b6cdc51f8b42f8adcf6236d8e3 Mon Sep 17 00:00:00 2001 From: Remi Rousselet Date: Mon, 27 Jun 2022 15:14:59 +0200 Subject: [PATCH 14/16] Commiting dependency override to make CI pass --- json_annotation/pubspec.yaml | 7 ++++--- json_serializable/pubspec.yaml | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/json_annotation/pubspec.yaml b/json_annotation/pubspec.yaml index 7b875c142..acf0e1741 100644 --- a/json_annotation/pubspec.yaml +++ b/json_annotation/pubspec.yaml @@ -12,6 +12,7 @@ dependencies: meta: ^1.4.0 # When changing JsonSerializable class. -# dev_dependencies: -# build_runner: ^2.0.0 -# json_serializable: any +dev_dependencies: + build_runner: ^2.0.0 + json_serializable: + path: ../json_serializable 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. From a5c6b66becfd6007ce0eda3e2c84c2fd79b841d6 Mon Sep 17 00:00:00 2001 From: Remi Rousselet Date: Tue, 28 Jun 2022 11:35:08 +0200 Subject: [PATCH 15/16] Update readme template --- json_serializable/README.md | 16 ++++++++-------- json_serializable/tool/readme/readme_template.md | 1 + 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/json_serializable/README.md b/json_serializable/README.md index 9a3083e3d..fd568cae1 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.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/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 6bf09879c37b523be5ff8ff650309d3839347f04 Mon Sep 17 00:00:00 2001 From: Remi Rousselet Date: Tue, 28 Jun 2022 11:35:31 +0200 Subject: [PATCH 16/16] Revert json_annotation pubspec --- json_annotation/pubspec.yaml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/json_annotation/pubspec.yaml b/json_annotation/pubspec.yaml index acf0e1741..7b875c142 100644 --- a/json_annotation/pubspec.yaml +++ b/json_annotation/pubspec.yaml @@ -12,7 +12,6 @@ dependencies: meta: ^1.4.0 # When changing JsonSerializable class. -dev_dependencies: - build_runner: ^2.0.0 - json_serializable: - path: ../json_serializable +# dev_dependencies: +# build_runner: ^2.0.0 +# json_serializable: any