0

I'm using Spring Data Repository to persistence objects. I'm trying to return them by REST web api (Jersey) and getting an error, but when i'm trying to return normal POJO object, all looks fine, Jersey parse object to JSON and i'm getting response 200 code.

@POST
@Path("/test")
@Produces( MediaType.APPLICATION_JSON )
public Document test() {
    Document d = documentRepository.findOne(123L);

    return d; // response code 500 without any stack trace

    return new Document(); // normal JSON object in response content
}

My dependencies for jersey:

    <dependency>
        <groupId>org.glassfish.jersey.ext</groupId>
        <artifactId>jersey-spring3</artifactId>
        <version>2.16</version>         
    </dependency>
    <dependency>
        <groupId>org.glassfish.jersey.media</groupId>
        <artifactId>jersey-media-json-processing</artifactId>
        <version>2.16</version>
    </dependency>

web.xml:

<servlet>
    <servlet-name>javax.ws.rs.core.Application</servlet-name>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>javax.ws.rs.core.Application</servlet-name>
    <url-pattern>/ws/*</url-pattern>
</servlet-mapping>

How can i return proxy object from spring data repository, or List of these objects ?

kris14an
  • 741
  • 7
  • 24
  • Did you make sure that documentRepository.findOne() method indeed returned proper document and not null ? – geekprogrammer Apr 02 '15 at 09:17
  • Yes, I debugged code, it is proxy object – kris14an Apr 02 '15 at 09:19
  • Please try like this: return Response.ok(d,MediaType.APPLICATION_JSON).build(); Change the return type to Response. – geekprogrammer Apr 02 '15 at 09:26
  • Same problem - code 500 – kris14an Apr 02 '15 at 09:29
  • Did you annotate your Document class with the annotation @XmlRootElement(javax.xml.bind.annotation.XmlRootElement)? And also it's better if you print the debug logs to console. http://stackoverflow.com/questions/26014184/jersey-returns-500-when-trying-to-return-an-xml-response – geekprogrammer Apr 02 '15 at 09:35
  • Not helped, but when i'm trying make a copy of object then Jersey return correct json. Only proxy object causes error. – kris14an Apr 02 '15 at 09:41
  • I'd advice you to print the logs to console so that you can know what's going wrong. I'm suspecting that something going wring while converting the proxy object(of Document type) to JSON, may be because you forgot to map some attributes correctly in Document bean. – geekprogrammer Apr 02 '15 at 09:46

0 Answers0