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
4 changes: 4 additions & 0 deletions json_serializable/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 6.9.6-wip

- Move `package:collection` to a dev dependency.

## 6.9.5

- Support the `analyzer: '>=6.9.0 <8.0.0'`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import 'package:analyzer/dart/constant/value.dart';
import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/dart/element/type.dart';
import 'package:collection/collection.dart';
import 'package:json_annotation/json_annotation.dart';
import 'package:source_gen/source_gen.dart';
import 'package:source_helper/source_helper.dart';
Expand Down Expand Up @@ -280,10 +279,11 @@ _ConverterMatch? _compatibleMatch(
) {
final converterClassElement = constantValue.type!.element as ClassElement;

final jsonConverterSuper =
converterClassElement.allSupertypes.singleWhereOrNull(
(e) => _jsonConverterChecker.isExactly(e.element),
);
final jsonConverterSuper = converterClassElement.allSupertypes
.where(
(e) => _jsonConverterChecker.isExactly(e.element),
)
.singleOrNull;

if (jsonConverterSuper == null) {
return null;
Expand Down
7 changes: 4 additions & 3 deletions json_serializable/lib/src/type_helpers/json_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/dart/element/type.dart';
import 'package:collection/collection.dart';
import 'package:json_annotation/json_annotation.dart';
import 'package:source_gen/source_gen.dart';
import 'package:source_helper/source_helper.dart';
Expand Down Expand Up @@ -79,7 +78,8 @@ class JsonHelper extends TypeHelper<TypeHelperContextWithConfig> {
final classElement = targetType.element;

final fromJsonCtor = classElement.constructors
.singleWhereOrNull((ce) => ce.name == 'fromJson');
.where((ce) => ce.name == 'fromJson')
.singleOrNull;

var output = expression;
if (fromJsonCtor != null) {
Expand Down Expand Up @@ -291,4 +291,5 @@ ClassConfig? _annotation(ClassConfig config, InterfaceType source) {

MethodElement? _toJsonMethod(DartType type) => type.typeImplementations
.map((dt) => dt is InterfaceType ? dt.getMethod('toJson') : null)
.firstWhereOrNull((me) => me != null);
.where((me) => me != null)
.firstOrNull;
3 changes: 1 addition & 2 deletions json_serializable/lib/src/type_helpers/map_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// BSD-style license that can be found in the LICENSE file.

import 'package:analyzer/dart/element/type.dart';
import 'package:collection/collection.dart';
import 'package:source_helper/source_helper.dart';

import '../constants.dart';
Expand Down Expand Up @@ -147,7 +146,7 @@ final _instances = [
];

ToFromStringHelper? _forType(DartType type) =>
_instances.singleWhereOrNull((i) => i.matches(type));
_instances.where((i) => i.matches(type)).singleOrNull;

/// Returns `true` if [keyType] can be automatically converted to/from String –
/// and is therefor usable as a key in a [Map].
Expand Down
4 changes: 2 additions & 2 deletions json_serializable/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: json_serializable
version: 6.9.5
version: 6.9.6-wip
description: >-
Automatically generate code for converting to and from JSON by annotating
Dart classes.
Expand All @@ -19,7 +19,6 @@ dependencies:
async: ^2.10.0
build: ^2.4.1
build_config: ^1.1.0
collection: ^1.17.0
dart_style: '>=2.3.7 <4.0.0'

# Use a tight version constraint to ensure that a constraint on
Expand All @@ -37,6 +36,7 @@ dev_dependencies:
path: ../shared_test
build_runner: ^2.4.6
build_verify: ^3.0.0
collection: ^1.17.0
logging: ^1.0.0
source_gen_test: ^1.0.6
test: ^1.24.4
Expand Down
3 changes: 1 addition & 2 deletions json_serializable/test/generic_files/generic_class.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

// ignore_for_file: inference_failure_on_instance_creation

import 'package:collection/collection.dart';
import 'package:json_annotation/json_annotation.dart';

import '../test_utils.dart';
Expand Down Expand Up @@ -146,7 +145,7 @@ class Issue980ParentClass {
other is Issue980ParentClass && deepEquals(list, other.list);

@override
int get hashCode => const DeepCollectionEquality().hash(list);
int get hashCode => deepHash(list);
}

@JsonSerializable(genericArgumentFactories: true)
Expand Down
2 changes: 2 additions & 0 deletions json_serializable/test/test_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@ import 'package:collection/collection.dart';

export 'package:_json_serial_shared_test/shared_test.dart';

int deepHash(List value) => const DeepCollectionEquality().hash(value);

bool deepEquals(dynamic a, dynamic b) =>
const DeepCollectionEquality().equals(a, b);