So we are converting our Java domain objects into Groovy and came across an issue that I hope someone has resolved.
Our class has a property that is of type java.sql.Date
This was working as a .java class, but as a .groovy it does not.
Here is what happens.
This domain object gets set into the Model that is attached to a JSONView object and returned to a web page. JSON has this great feature that it calls every single getter method of objects returned in the Model. Which means it is calling .getHours() in that Date property. The current implementation of getHours() is just
This may not be a good long term solution but couldn't you just create your own date class that extends java.sql.Date and override that one particular method that is causing you fits?
Gregg Bolinger wrote:This may not be a good long term solution but couldn't you just create your own date class that extends java.sql.Date and override that one particular method that is causing you fits?
Yeah that was one of the hacks that we thought of, but threw it out because of that.
Mark
Peter Ledbrook
author
Greenhorn
Joined: Jul 15, 2009
Posts: 25
posted
0
Hi,
I can't understand why there would be a difference between the Java and Groovy domain objects. How are they defined? Is the JSON serialiser (I assume that's what's triggering the exception) processing the date property when the domain object is Java?
The only thing I can think of is that Groovy automatically generates getter and setter methods for any class fields that have no scope. You can prevent the creation of those methods by adding private, protected or public to the field.
I can't understand why there would be a difference between the Java and Groovy domain objects. How are they defined? Is the JSON serialiser (I assume that's what's triggering the exception) processing the date property when the domain object is Java?
The only thing I can think of is that Groovy automatically generates getter and setter methods for any class fields that have no scope. You can prevent the creation of those methods by adding private, protected or public to the field.
Cheers,
Peter
That is basically what is happening, as a Java object I saw that there wasn't any getters or setters for the two Date fields, so when changing them to Groovy, Groovy automatically created getters and setters, So I will just change it to private. But it will have to wait till the next sprint now. If we can get to it.
Vyas Sanzgiri wrote:I didnt get you Mark, "wait" meaning?
We are using Agile/Scrum at our company, so we work in 2 week springs. Since we were at the end of the refactor sprint that had us doing the java to groovy conversion, it was too late to fix this problem and get a release done. So I have to change that java class to groovy later in another sprint. So I have to wait for another sprint that putting this story/task on will make sense and QA and the other teams allow us to put it on the sprint.