If different objects return the same hashCode, it may cause circular reference detection.
Here is a reproducible example.
import 'package:dart_json_mapper/dart_json_mapper.dart';
import 'main.mapper.g.dart';
@jsonSerializable
class A {
final int a;
A(this.a);
@override
bool operator ==(Object other) => runtimeType == other.runtimeType && a == (other as A).a;
@override
int get hashCode => a.hashCode;
}
@jsonSerializable
class B {
final A a;
B(this.a);
}
void main() {
initializeJsonMapper();
JsonMapper.serialize([
A(1),
A(1),
B(A(1)),
]);
}
If different objects return the same hashCode, it may cause circular reference detection.
Here is a reproducible example.
Since this error only occurs when hashCode has been overridden, I assume it is related to the following object key generation code.
https://github.com/k-paxian/dart-json-mapper/blob/bfc5f55fa8e52414e6d9bd841bca55314d3e22ca/mapper/lib/src/mapper.dart#L266
So, changing this to identityHashCode may be enough to solve this problem, but I am not sure.