Please use the Apache issue tracking system for new NetBeans issues ( !!
Bug 205394 - StackOverFlowError when generating RESTful representation using Entities
StackOverFlowError when generating RESTful representation using Entities
Product: webservices
Classification: Unclassified
Component: REST
: P3 (vote)
: 7.2
Assigned To: Denis Anisimov
Depends on:
  Show dependency treegraph
Reported: 2011-11-22 00:36 UTC by arungupta
Modified: 2012-01-12 16:00 UTC (History)
3 users (show)

See Also:
Issue Type: DEFECT


Note You need to log in before you can comment on or make changes to this bug.
Description arungupta 2011-11-22 00:36:07 UTC
Create a new Web project
Generate RESTful entities for Customer database using "RESTful Web services from Database..."
Access the complete set of customers at:


The default representation is "application/xml" and looks good.

Change the @Produces for 

    @Produces({"application/json", "application/xml"})
    public List<Customer> findAll() {
        return super.findAll();


    public List<Customer> findAll() {
        return super.findAll();

Access the list again and a StackOverFlow error is thrown as: 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
Comment 1 David Konecny 2011-11-22 02:01:15 UTC
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?
Comment 2 David Konecny 2011-11-22 02:01:58 UTC
Something wrong with BugZilla right now - it does not allow me to move the issue to webservices/rest category.
Comment 3 Denis Anisimov 2011-11-22 09:25:15 UTC
@org.codehaus.jackson.annotate.JsonIgnore annotation 
( ) 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.
Comment 4 japod 2012-01-02 14:08:05 UTC
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.

Comment 5 Denis Anisimov 2012-01-11 12:37:22 UTC
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.
Comment 6 Quality Engineering 2012-01-12 16:00:53 UTC
Integrated into 'main-golden'
User: Denis Anisimov <>
Log: Fix for BZ#205394 - StackOverFlowError when generating RESTful representation using Entities

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2014, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo