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
For example, a String value such as 2023-12-11T17:12 should be successfully converted to the corresponding LocalDateTime value.
Actual Behaviour
The default data binding fails to convert such String values. For example, in my class Scenario which has a LocalDateTime field dateTime, the ScenarioControllersave() method fails on data binding with a message like:
scenario.errors org.grails.datastore.mapping.validation.ValidationErrors: 1 errors
Field error in object 'Scenario' on field 'dateTime': rejected value [2023-12-11T17:12]; codes [Scenario.dateTime.typeMismatch.error,Scenario.dateTime.typeMismatch,scenario.dateTime.typeMismatch.error,scenario.dateTime.typeMismatch,typeMismatch.Scenario.dateTime,typeMismatch.dateTime,typeMismatch.java.time.LocalDateTime,typeMismatch]; arguments [dateTime]; default message [Text '2023-12-11T17:12' could not be parsed at index 10]
This problem can be worked around by definining a specific data binding following the example of the BindUsing annotation provided in the Grails 6.1.0 docs. In my case, the following works:
I suppose this hints that the default data binding for LocalDateTime should use its parse() method.
Steps To Reproduce
Create a domain class with a java.time.LocalDateTime field; create the CRUD for it; run the application and create a new instance of that domain class; enter the desired local date and time and save.
I realized I probably should have mentioned that the format including the T between the date and time components of the string is generated in my case by HTML input type="datetime-local" and not g:datePicker.
Adds a new converter named `LocalDateTimeConverter` which will automatically convert `String` or `LocalDateTime` values when using data binder.
Fixes#13280
Expected Behavior
A domain class having a field declared to be
java.time.LocalDateTime
should have default data binding that expects the standard ISO-8601 string formats defined in that class.For example, a
String
value such as2023-12-11T17:12
should be successfully converted to the correspondingLocalDateTime
value.Actual Behaviour
The default data binding fails to convert such
String
values. For example, in my classScenario
which has aLocalDateTime
fielddateTime
, theScenarioController
save()
method fails on data binding with a message like:This problem can be worked around by definining a specific data binding following the example of the BindUsing annotation provided in the Grails 6.1.0 docs. In my case, the following works:
import grails.databinding.BindUsing
...
I suppose this hints that the default data binding for
LocalDateTime
should use itsparse()
method.Steps To Reproduce
Create a domain class with a java.time.LocalDateTime field; create the CRUD for it; run the application and create a new instance of that domain class; enter the desired local date and time and save.
Environment Information
Example Application
This application has a single domain class with a LocalDateTime field
Version
6.1.0
The text was updated successfully, but these errors were encountered: