• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Groovy/JSON/sql.Date

 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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

throw new IllegalArgumentException();

So, now as a groovy object the page gets this exception and won't display. As a java object it all works perfectly, no exception.

Thanks

Mark
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
author
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

Cheers,

Peter
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Peter Ledbrook wrote: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.

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.

Thanks Peter.

Mark
 
Ranch Hand
Posts: 686
Netbeans IDE Chrome Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I didnt get you Mark, "wait" meaning?
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.

Mark
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic