You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
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
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 asString
, and when retrieved I receive an exception. Details follow.Steps I took:
grails create-app test-mongo --profile rest-api
build.config
:implementation 'org.grails.plugins:mongodb:7.3.0'
save
&list
endpoints), withLocalDate
andZonedDateTime
propsapplication.yml
POST
to /foo successful, but serializes LocalDate and ZonedDateTime asString
. OnGET
, receive the following error: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
The text was updated successfully, but these errors were encountered: