This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.
Create a new Web project Generate RESTful entities for Customer database using "RESTful Web services from Database..." Access the complete set of customers at: http://localhost:8080/CustomerREST/restful/customers/ The default representation is "application/xml" and looks good. Change the @Produces for @GET @Override @Produces({"application/json", "application/xml"}) public List<Customer> findAll() { return super.findAll(); } to @GET @Override @Produces({"application/json"}) public List<Customer> findAll() { return super.findAll(); } Access the list again and a StackOverFlow error is thrown as: org.codehaus.jackson.map.JsonMappingException: Infinite recursion (StackOverflowError) (through reference chain: entities.MicroMarket["customerCollection"]->org.eclipse.persistence.indirection.IndirectList[0]->entities.Customer["zip"]->entities.MicroMarket["customerCollection"]->org.eclipse.persistence.indirection.IndirectList[0]->entities.Customer["zip"]->entities.MicroMarket["customerCollection"]->org.eclipse.persistence.indirection.IndirectList[0]->entities.Customer["zip"]->entities.MicroMarket["customerCollection"]->org.eclipse.persistence.indirection.Indirect
This sounds familiar - I'm been prototyping some JavaScript app and I think I bumped into the same problem. I cannot remember where the problem was - sounds like Java code generated does not indicate where to stop object traversal and marshalling? But if it works for XML then why JSON fails?
Something wrong with BugZilla right now - it does not allow me to move the issue to webservices/rest category.
@org.codehaus.jackson.annotate.JsonIgnore annotation ( http://jackson.codehaus.org/1.0.1/javadoc/org/codehaus/jackson/annotate/JsonIgnore.html ) similar to javax.xml.bind.annotation.XmlTransient. The latter annotation is used to prevent recursive navigation over XML elements. F.e. DiscountCode class has method getCustomerCollection() annotated with @XmlTransient. That's why the problem is absent for XML mime type. @JsonIgnore should be used at the same places where @XmlTransient. It seems this issue is related newer Jersey libraries. I believe all works fine without @JsonIgnore annotation with old Jersey 1.3.
To avoid the necessity for adding @JsonIgnore everywhere you might want to provide your customized Jackson object mapper. Then Jackson should take @XmlTransient annotation into account when serializing JSON. Details are available at [1]. A complete example is available at [2], look at the MyObjectMapperProvider class. I believe such a provider could be auto-generated by NetBeans. [1]http://wiki.fasterxml.com/JacksonJAXBAnnotations [2]http://search.maven.org/remotecontent?filepath=com/sun/jersey/samples/jacksonjsonprovider/1.11/jacksonjsonprovider-1.11-project.zip
The generation process is automatic and already exist for XmlTransient. So it is easier here to add just one more annotation in the process of generation instead of generate additional Mapper provider class. web-main#1ec54cbb74df
Integrated into 'main-golden' Changeset: http://hg.netbeans.org/main-golden/rev/1ec54cbb74df User: Denis Anisimov <ads@netbeans.org> Log: Fix for BZ#205394 - StackOverFlowError when generating RESTful representation using Entities