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

Default conversion for $date type should be Instant #4864

Closed
mikeyg123 opened this issue Dec 24, 2024 · 2 comments
Closed

Default conversion for $date type should be Instant #4864

mikeyg123 opened this issue Dec 24, 2024 · 2 comments
Labels
status: feedback-reminder We've sent a reminder that we need additional information before we can continue status: waiting-for-feedback We need additional information before we can continue

Comments

@mikeyg123
Copy link

When deserialising to a Map or similar flexible type $date fields get deserialised as java.util.date
e.g: something like
mongoTemplate.find(query, Map.class, "myCollection")
will convert:

  {"time": {
    "$date": "2024-10-18T16:32:51.058Z"
  }}

returning a Date for the "time" field.
java.util.Date is an antiquated, broken and difficult to use class. Since timezone ('z') information is specified in the value the natural default conversion would be java.time.Instant. (or possibly a ZonedDateTime but this is possibly less convenient in the majority of cases)
In general all uses of java.util.Date and java.util.Calendar should be removed.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Dec 24, 2024
@christophstrobl
Copy link
Member

Have you tried to configure the mapping to make use of the MongoClients capability for java.time types via useNativeDriverJavaTimeCodecs as mentioned in the reference documentation?

If that does not work for you and you'd like us to spend some time investigating, please take the time to provide a complete minimal sample (something that we can unzip or git clone, build, and deploy) that reproduces the problem.

@christophstrobl christophstrobl added status: waiting-for-feedback We need additional information before we can continue and removed status: waiting-for-triage An issue we've not yet triaged labels Dec 28, 2024
@spring-projects-issues
Copy link

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

@spring-projects-issues spring-projects-issues added the status: feedback-reminder We've sent a reminder that we need additional information before we can continue label Jan 4, 2025
@mikeyg123 mikeyg123 closed this as not planned Won't fix, can't repro, duplicate, stale Jan 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: feedback-reminder We've sent a reminder that we need additional information before we can continue status: waiting-for-feedback We need additional information before we can continue
Projects
None yet
Development

No branches or pull requests

3 participants