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

[Grails 5] Unclear how to enable codecs for Java 8 date/time class marshalling #539

Open
MichaelJRussell opened this issue Jun 27, 2022 · 0 comments

Comments

@MichaelJRussell
Copy link

I've reviewed the documentation at https://gorm.grails.org/latest/mongodb/manual/, I don't see how to take advantage of the codecs in groovy.org.grails.datastore.bson.codecs. My assumption was that just adding the MongoDb plugin to my application would automatically enable marshalling/unmarshalling of Java 8 types such as LocalDate and ZonedDateTime, but instead they're serialized as String, and when retrieved I receive an exception. Details follow.

Steps I took:

  • Create a new Grails (v5.1.7) app: grails create-app test-mongo --profile rest-api
  • Add the Gorm MongoDb plugin to build.config: implementation 'org.grails.plugins:mongodb:7.3.0'
  • Create a trivial Domain and associated Controller with save & list endpoints), with LocalDate and ZonedDateTime props
  • Add MongoDb connection settings to local dev config in application.yml

POST to /foo successful, but serializes LocalDate and ZonedDateTime as String. On GET, receive the following error:

Failed to convert property value of type 'java.lang.String' to required type 'java.time.LocalDate' for property 'dob'; nested exception is java.lang.IllegalStateException: Cannot convert value of type 'java.lang.String' to required type 'java.time.LocalDate' for property 'dob': no matching editors or conversion strategy found

I also tried adding this: implementation 'org.grails:grails-datastore-gorm-mongodb:7.3.0', but same result.

Example repo: https://github.com/MichaelJRussell/mongo-test

@MichaelJRussell MichaelJRussell changed the title [Grails 5] Unclear how to enable default codecs for Java 8 date/time class marshalling [Grails 5] Unclear how to enable codecs for Java 8 date/time class marshalling Jun 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant