1
votes

I have a issue where, I have a converter class say called aConverter as such:

@XmlRootElement(name = "aConverter")
public class aConverter implements ConverterBase{

      private A a;
      private Set<B> bs;
      /// some constructor code here
      ...
      @XmlElement(name="B")
      public Set<B> getBs() {
                bs = a.getBs();
                return bs;
      }

      public void setBs(Set<B> bs) {
                a.setBs(bs);
      }
}

Class A and B are defined respectively in a cyclic fashion:

public class A {
       private Set <B> bs;

       //constructor code here
       ... 

       public Set<B> getBs() {
          return this.bs;
       }
       public void setBs(Set<B> bs) {
          this.bs = bs;
       }
}

>

public class B {
       private A a;

       // some constructor code here
       ...

       public A getA() {
              return this.a;
       }
       public void setA(A a) {
              this.a = a;
       }
}

Now, when I the webservice I'm seeing the following error:

[com.sun.istack.internal.SAXException2: A cycle is detected in the object graph. This will cause infinitely deep XML: B@1105452 -> A@1 -> B@1105452] at com.sun.jersey.core.provider.jaxb.AbstractRootElementProvider.writeTo(AbstractRootElementProvider.java:152) at com.sun.jersey.spi.container.ContainerResponse.write(ContainerResponse.java:294) at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1140) at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1053) at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1043) at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:406) at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:477) at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:662) at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489) at java.lang.Thread.run(Thread.java:680) Caused by: javax.xml.bind.MarshalException - with linked exception:

I'm really out of ideas here, any feeback on this would be really nice.

Cheers!

2

2 Answers

1
votes

In EclipseLink JAXB (MOXy) we introduced the @XmlInverseReference extension to solve this issue. For an example of how this can be leveraged in a JAX-RS service check out:

0
votes

You can use @XmlTransient annotation. See this page for more.