DateTime doesn't work as expected
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 x2 = DateTimeExampleMapper.fromJson(x.toJson());
print("this should be true, it's ${x == x2}"); // "false"
}
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.
Amazing package but this issue deserves more attention since it is very fundamental—it’d be great to get an update. Thanks! 🙏
Is there a temporary solution to fix this?
As a workaround, you can put DateTimeMapper.encodingMode = DateTimeEncoding.iso8601String in your main().
As a workaround, you can put
DateTimeMapper.encodingMode = DateTimeEncoding.iso8601Stringin yourmain().
Thank you!