Skip to content

Commit 9b8050c

Browse files
authored
json_serializable: fix readme spelling, DRY up some type logic (#1212)
1 parent f94edb2 commit 9b8050c

File tree

7 files changed

+14
-17
lines changed

7 files changed

+14
-17
lines changed

json_serializable/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
## 6.4.2-dev
2+
13
## 6.4.1
24

35
- Fixed a bug when an `@JsonSerializable` class uses a mixin with fields.

json_serializable/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ For [`Map`], the key value must be one of
167167
If you want to use types that are not supported out-of-the-box or if you want to
168168
customize the encoding/decoding of any type, you have a few options.
169169

170-
1. If you own/cotrol the desired type, add a `fromJson` constructor and/or a
170+
1. If you own/control the desired type, add a `fromJson` constructor and/or a
171171
`toJson()` function to the type. Note: while you can use `json_serializable`
172172
for these types, you don't have to! The generator code only looks for these
173173
methods. It doesn't care how they were created.

json_serializable/lib/src/type_helpers/map_helper.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,20 +167,21 @@ void _checkSafeKeyType(String expression, DartType keyArg) {
167167
throw UnsupportedTypeError(
168168
keyArg,
169169
expression,
170-
'Map keys must be one of: ${_allowedTypeNames.join(', ')}.',
170+
'Map keys must be one of: ${allowedMapKeyTypes.join(', ')}.',
171171
);
172172
}
173173

174174
/// The names of types that can be used as [Map] keys.
175175
///
176176
/// Used in [_checkSafeKeyType] to provide a helpful error with unsupported
177177
/// types.
178-
Iterable<String> get _allowedTypeNames => const [
178+
List<String> get allowedMapKeyTypes => [
179179
'Object',
180180
'dynamic',
181181
'enum',
182182
'String',
183-
].followedBy(_instances.map((i) => i.coreTypeName));
183+
..._instances.map((i) => i.coreTypeName)
184+
];
184185

185186
extension on DartType {
186187
bool get isSimpleJsonTypeNotDouble =>

json_serializable/lib/type_helper.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export 'src/type_helpers/enum_helper.dart';
1414
export 'src/type_helpers/iterable_helper.dart';
1515
export 'src/type_helpers/json_converter_helper.dart';
1616
export 'src/type_helpers/json_helper.dart';
17-
export 'src/type_helpers/map_helper.dart';
17+
export 'src/type_helpers/map_helper.dart' show MapHelper;
1818
export 'src/type_helpers/uri_helper.dart';
1919
export 'src/type_helpers/value_helper.dart';
2020
export 'src/unsupported_type_error.dart';

json_serializable/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: json_serializable
2-
version: 6.4.1
2+
version: 6.4.2-dev
33
description: >-
44
Automatically generate code for converting to and from JSON by annotating
55
Dart classes.

json_serializable/tool/readme/readme_template.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ For `core:Map`, the key value must be one of
103103
If you want to use types that are not supported out-of-the-box or if you want to
104104
customize the encoding/decoding of any type, you have a few options.
105105

106-
1. If you own/cotrol the desired type, add a `fromJson` constructor and/or a
106+
1. If you own/control the desired type, add a `fromJson` constructor and/or a
107107
`toJson()` function to the type. Note: while you can use `json_serializable`
108108
for these types, you don't have to! The generator code only looks for these
109109
methods. It doesn't care how they were created.

json_serializable/tool/test_type_builder.dart

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import 'dart:async';
77
import 'package:build/build.dart';
88
import 'package:collection/collection.dart';
99
import 'package:dart_style/dart_style.dart';
10+
import 'package:json_serializable/src/type_helpers/map_helper.dart';
1011

1112
import 'shared.dart';
1213
import 'test_type_data.dart';
@@ -96,16 +97,9 @@ final _typesToTest = {
9697
..._collectionTypes,
9798
};
9899

99-
const mapKeyTypes = {
100-
'BigInt',
101-
'DateTime',
102-
'dynamic',
103-
customEnumType,
104-
'int',
105-
'Object',
106-
'String',
107-
'Uri',
108-
};
100+
Iterable<String> get mapKeyTypes =>
101+
allowedMapKeyTypes.map((e) => e == 'enum' ? customEnumType : e).toList()
102+
..sort(compareAsciiLowerCase);
109103

110104
final _iterableGenericArgs = ([
111105
..._trivialTypesToTest.keys,

0 commit comments

Comments
 (0)