Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions json_serializable/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
- Require `dart_style: ^3.0.0`
- Require `meta: ^1.15.0`
- Require `source_helper: ^1.3.6`
- Require `source_gen: ^3.1.0`, stop using deprecated `TypeChecker.fromRuntime`
and use the new `TypeChecker.typeNamed` instead.

## 6.10.0

Expand Down
8 changes: 6 additions & 2 deletions json_serializable/lib/src/enum_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,9 @@ Object? _generateEntry({
required JsonEnum jsonEnum,
required DartType targetType,
}) {
final annotation = const TypeChecker.fromRuntime(
final annotation = const TypeChecker.typeNamed(
JsonValue,
inPackage: 'json_annotation',
).firstAnnotationOfExact(field);

if (annotation == null) {
Expand Down Expand Up @@ -144,7 +145,10 @@ Object? _generateEntry({
}
}

const _jsonEnumChecker = TypeChecker.fromRuntime(JsonEnum);
const _jsonEnumChecker = TypeChecker.typeNamed(
JsonEnum,
inPackage: 'json_annotation',
);

JsonEnum _fromAnnotation(DartObject? dartObject) {
if (dartObject == null) {
Expand Down
6 changes: 5 additions & 1 deletion json_serializable/lib/src/field_helpers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,8 @@ List<FieldElement2> createSortedFieldSet(ClassElement2 element) {
return fields.map((fs) => fs.field).toList(growable: false);
}

const _dartCoreObjectChecker = TypeChecker.fromRuntime(Object);
const _dartCoreObjectChecker = TypeChecker.typeNamed(
Object,
inPackage: 'core',
inSdk: true,
);
2 changes: 1 addition & 1 deletion json_serializable/lib/src/json_enum_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import 'package:source_gen/source_gen.dart';
import 'enum_utils.dart';

class JsonEnumGenerator extends GeneratorForAnnotation<JsonEnum> {
const JsonEnumGenerator();
const JsonEnumGenerator() : super(inPackage: 'json_annotation');

@override
List<String> generateForAnnotatedElement(
Expand Down
3 changes: 2 additions & 1 deletion json_serializable/lib/src/json_key_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@ bool _interfaceTypesEqual(DartType a, DartType b) {
const jsonKeyNullForUndefinedEnumValueFieldName =
'JsonKey.nullForUndefinedEnumValue';

final _nullAsUnknownChecker = TypeChecker.fromRuntime(
final _nullAsUnknownChecker = TypeChecker.typeNamed(
JsonKey.nullForUndefinedEnumValue.runtimeType,
inPackage: 'json_annotation',
);
2 changes: 1 addition & 1 deletion json_serializable/lib/src/json_literal_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import 'package:source_gen/source_gen.dart';
import 'package:source_helper/source_helper.dart';

class JsonLiteralGenerator extends GeneratorForAnnotation<JsonLiteral> {
const JsonLiteralGenerator();
const JsonLiteralGenerator() : super(inPackage: 'json_annotation');

@override
Future<String> generateForAnnotatedElement(
Expand Down
3 changes: 2 additions & 1 deletion json_serializable/lib/src/json_serializable_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ class JsonSerializableGenerator

JsonSerializable get config => _settings.config.toJsonSerializable();

JsonSerializableGenerator.fromSettings(this._settings);
JsonSerializableGenerator.fromSettings(this._settings)
: super(inPackage: 'json_annotation');

/// Creates an instance of [JsonSerializableGenerator].
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,4 +331,7 @@ _ConverterMatch? _compatibleMatch(
return null;
}

const _jsonConverterChecker = TypeChecker.fromRuntime(JsonConverter);
const _jsonConverterChecker = TypeChecker.typeNamed(
JsonConverter,
inPackage: 'json_annotation',
);
3 changes: 2 additions & 1 deletion json_serializable/lib/src/type_helpers/json_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,9 @@ ClassConfig? _annotation(ClassConfig config, InterfaceType source) {
if (source.isEnum) {
return null;
}
final annotations = const TypeChecker.fromRuntime(
final annotations = const TypeChecker.typeNamed(
JsonSerializable,
inPackage: 'json_annotation',
).annotationsOfExact(source.element3, throwOnUnresolved: false).toList();

if (annotations.isEmpty) {
Expand Down
5 changes: 4 additions & 1 deletion json_serializable/lib/src/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ import 'package:source_helper/source_helper.dart';
import 'shared_checkers.dart';
import 'type_helpers/config_types.dart';

const _jsonKeyChecker = TypeChecker.fromRuntime(JsonKey);
const _jsonKeyChecker = TypeChecker.typeNamed(
JsonKey,
inPackage: 'json_annotation',
);

/// If an annotation exists on `element` the source is a 'real' field.
/// If the result is `null`, check the getter – it is a property.
Expand Down
2 changes: 1 addition & 1 deletion json_serializable/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ dependencies:
path: ^1.9.0
pub_semver: ^2.1.4
pubspec_parse: ^1.0.0
source_gen: ^3.0.0
source_gen: ^3.1.0
source_helper: ^1.3.6

dev_dependencies:
Expand Down