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 get _allowedTypeNames => const [ +List 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 get mapKeyTypes => + allowedMapKeyTypes.map((e) => e == 'enum' ? customEnumType : e).toList() + ..sort(compareAsciiLowerCase); final _iterableGenericArgs = ([ ..._trivialTypesToTest.keys,