mehandih / grails-jaxrs

Automatically exported from code.google.com/p/grails-jaxrs
0 stars 0 forks source link

POST and PUT don't work with Date #46

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1.
create domain class such as:
package grails01
class Person {
    String firstName
    String lastName
    Date birthday
    static constraints = {
    }
}

2.
install-plugin jaxrs
generate-resources grails01.Person, 
run-app

3.
The GET methode will produce an xml data such as:
<person id="1">
<birthday>2005-01-01 00:00:00</birthday>
<firstName>Simba</firstName>
<lastName>The Cat</lastName>
</person>

but if I send xml data using POST, it doesn't work:

<person>
<birthday>2000-07-12 00:00:00</birthday>
<firstName>Lion</firstName>
<lastName>King</lastName>
</person>

What is the expected output? What do you see instead?
new entry in data base should be created
but I get following error:
Error 500: Executing action [handle] of controller 
[org.grails.jaxrs.JaxrsController] in plugin [jaxrs] caused exception: Cannot 
get property 'id' on null object
Servlet: grails
URI: /grails05/grails/jaxrs.dispatch
Exception Message: Cannot get property 'id' on null object
Caused by: Cannot get property 'id' on null object
Class: JaxrsController
At Line: [48]
Code Snippet:

and stacktrace:
java.lang.NullPointerException: Cannot get property 'id' on null object

    at org.grails.jaxrs.response.Responses.created(Responses.groovy:47)

    at org.grails.jaxrs.response.Responses$created.callStatic(Unknown Source)

    at org.grails.jaxrs.response.Responses$created.callStatic(Unknown Source)

    at grails05.PersonCollectionResource.create(PersonCollectionResource.groovy:20)

    at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$ResponseOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:186)

    at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:70)

    at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:279)

    at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:86)

    at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:136)

    at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:74)

    at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1347)

    at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1279)

    at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1229)

    at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1219)

    at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:419)

    at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:537)

    at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:699)

    at org.grails.jaxrs.web.JaxrsContext$JaxrsServiceImpl.process(JaxrsContext.java:192)

    at org.grails.jaxrs.web.JaxrsService$process.call(Unknown Source)

    at org.grails.jaxrs.JaxrsController$_closure1.doCall(JaxrsController.groovy:48)

    at org.grails.jaxrs.JaxrsController$_closure1.doCall(JaxrsController.groovy)

    at org.grails.jaxrs.web.JaxrsFilter.doFilterInternal(JaxrsFilter.java:46)

    at java.lang.Thread.run(Thread.java:680)

What version of the product are you using? On what operating system?
jdk 1.6, grails 1.3.7, jaxrs 0.4 and 0.5, windows,macosx

Please provide any additional information below.

It works if I change the date format to:

<person>
<birthday>Jul 12, 2000 00:00:00</birthday>
<firstName>Lion</firstName>
<lastName>King</lastName>
</person>

What should I do so the xml/json data send to the server and received 
from the server use the same date format?

Original issue reported on code.google.com by cahya.wi...@gmail.com on 21 Aug 2011 at 10:29

GoogleCodeExporter commented 8 years ago
This is not a grails-jaxrs issue but a Grails issue. Well, not really an issue: 
you need to define a custom property editor for converting date Strings to Date 
objects. What I tried is 
http://blog.myti.it/post/441330811/custom-property-editor-for-grails and it 
works nicely.

For custom date representations during XML rendering (i.e. domain object to XML 
conversion) please refer to the Grails documentation.

Original comment by krass...@googlemail.com on 28 Aug 2011 at 5:41

GoogleCodeExporter commented 8 years ago
Should you still see this as a bug please create a JIRA ticket for Grails 
directly.

Original comment by krass...@googlemail.com on 28 Aug 2011 at 5:42