Skip to content

Commit 79f4ff6

Browse files
committed
chore: add test for alias type
1 parent 0632c5b commit 79f4ff6

File tree

4 files changed

+13
-2
lines changed

4 files changed

+13
-2
lines changed

json_annotation/lib/src/json_value.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class JsonValue {
1212
/// Optional values that can be used when deserializing.
1313
///
1414
/// The elements of [aliases] must be either [String] or [int].
15-
final Set<Object?> aliases;
15+
final Set<Object> aliases;
1616

1717
const JsonValue(this.value, {this.aliases = const {}});
1818
}

json_serializable/lib/src/enum_utils.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ List<Object?> _generateAliases({
216216
final targetTypeCode = typeToCode(targetType);
217217
throw InvalidGenerationSourceError(
218218
'The `JsonValue` annotation on `$targetTypeCode.${field.name}` aliases '
219-
'should all be of type String, or int.',
219+
'should all be of type String or int.',
220220
element: field,
221221
);
222222
}

json_serializable/test/json_serializable_test.dart

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ Future<void> main() async {
3232
jsonEnumTestReader,
3333
const JsonEnumGenerator(),
3434
expectedAnnotatedTests: {
35+
'EnumAliasNotSupportType',
3536
'EnumValueIssue1147',
3637
'EnumValueNotAField',
3738
'EnumValueNotSupportType',

json_serializable/test/src/_json_enum_test_input.dart

+10
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@
55
import 'package:json_annotation/json_annotation.dart';
66
import 'package:source_gen_test/annotations.dart';
77

8+
@ShouldThrow(
9+
'The `JsonValue` annotation on `EnumAliasNotSupportType.one` aliases should '
10+
'all be of type String or int.',
11+
)
12+
@JsonEnum(alwaysCreate: true)
13+
enum EnumAliasNotSupportType {
14+
@JsonValue('one', aliases: {#one})
15+
one,
16+
}
17+
818
@ShouldGenerate(r'''
919
// ignore: unused_element
1020
const _$EnumValueIssue1147EnumMap = {

0 commit comments

Comments
 (0)