schultek / dart_mappable

Improved json serialization and data classes with full support for generics, inheritance, customization and more.
https://pub.dev/packages/dart_mappable
MIT License
165 stars 23 forks source link

DateTime doesn't work as expected #242

Open lukepighetti opened 1 week ago

lukepighetti commented 1 week ago

There are many issues on this already but I'll just illustrate it quite simply. The way dart_mappable handles dates out-of-the-box is unlike anything I've ever seen in a serialization package. Quite simply, any model with a DateTime cannot pass equality checks after it's been serialized and deserialized.

@MappableClass()
class DateTimeExample with DateTimeExampleMappable {
  final DateTime timestamp;

  DateTimeExample({required this.timestamp});
}

void main() async {
  final x = DateTimeExample(timestamp: DateTime(2020));
  final json = x.toJson();
  final x2 = DateTimeExampleMapper.fromJson(json);
  print("this should be true, it's ${x == x2}"); // "false"
}
schultek commented 1 week ago

There are some decisions I would do otherwise now, but I simply don't want to make a breaking change now.

DateTime encoding is one of them.

When I make a new major version I can change it.