Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DateTime doesn't work as expected #242

Open
lukepighetti opened this issue Nov 14, 2024 · 4 comments
Open

DateTime doesn't work as expected #242

lukepighetti opened this issue Nov 14, 2024 · 4 comments
Labels
enhancement New feature or improvement

Comments

@lukepighetti
Copy link

lukepighetti commented Nov 14, 2024

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
Copy link
Owner

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.

@devberkay
Copy link

Amazing package but this issue deserves more attention since it is very fundamental—it’d be great to get an update. Thanks! 🙏

@cheymos
Copy link

cheymos commented Jan 13, 2025

Is there a temporary solution to fix this?

@schultek
Copy link
Owner

As a workaround, you can put DateTimeMapper.encodingMode = DateTimeEncoding.iso8601String in your main().

@schultek schultek added the enhancement New feature or improvement label Jan 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or improvement
Projects
None yet
Development

No branches or pull requests

4 participants