users@jersey.java.net

RE: [Jersey] net.sf.json.JSONException: There is a cycle in the hierarchy!

From: cgswtsu78 <cgray_at_proofpoint.com>
Date: Wed, 16 Dec 2009 11:24:43 -0800 (PST)

Hi Paul,

 

I do Have ChartSpecification annotated, see below...anything wrong with
that?

 

 

import java.io.Serializable;

import java.util.List;

import java.util.Map;

 

import javax.xml.bind.annotation.XmlRootElement;

 

import org.eclipse.birt.chart.model.attribute.ChartDimension;

 

@XmlRootElement(name="ChartSpecification")

public class ChartSpecification implements Serializable{

      

      private static final long serialVersionUID = -295197254459282522L;

      private List xAxis;

      private List yAxis;

      private Double width;

      private Double height;

      private ChartDimension chartOrientation;

      private String imagePath;

      private Object wrapper;

      private String chartType;

      private String chartSubType;

      private String chartTitle;

      private String oSeriesIdentifier;

      private String desc;

      private Map whereClauseStmts;

}

 

________________________________

From: Paul Sandoz [via Jersey]
[mailto:ml-node+4177396-1484885178_at_n2.nabble.com]
Sent: Wednesday, December 16, 2009 11:13 AM
To: Colin Gray
Subject: Re: [Jersey] net.sf.json.JSONException: There is a cycle in the
hierarchy!

 

Hi,

The exception you are getting is because Jersey does not know how to
convert an instance of ChartSpecification to JSON.

You need to annotate ChartSpecification with the JAXB annotation
@XmlRootElement.

If you use Jackson JAX-RS support then you do not need to annotate
ChartSpecification.

Paul.

On Dec 16, 2009, at 7:12 PM, cgswtsu78 wrote:


>
> Hi Jakub,
>
> Thanks for the quick reply. I did find an Entity Provider and was
> using it.
> I removed it from the classpath and I get the below exception when I

> perform
> HTTP GET against the /topspamsenderchart resource. Is the Jersey
> provided
> writer implemented by default or is there some extra configuration I

> need to
> do? I have experimented with Jackson yet and would like to try the
> Jersey
> writer, but it looks like I have some dependency issue. I did some
> searching and it seems to be a JSON dependency issue, but I do have
> the
> json-lib-2.2.3-jdk15.jar on the classpath...so I'm a bit stumped
> here. Any
> ideas?
>
> Resource Method:
> @GET
> @Path("/topspamsenderchart")
> @Produces("application/json")
> public Response getTopSpamSenderChartTest1() throws Exception{
>
> ChartSpecification chartSpec = new ChartSpecification();
>
> chartSpec.setWidth(new Double(700));
> chartSpec.setHeight(new Double(500));
> chartSpec.setChartType("4");
>
> return Response.ok(chartSpec).type("application/json").build();
> }
>
> Exception:
> javax.ws.rs.WebApplicationException
> at
> com
> .sun
> .jersey.spi.container.ContainerResponse.write(ContainerResponse.java:
> 253)
> at
> com
> .sun
> .jersey
> .server
> .impl
> .application
> .WebApplicationImpl._handleRequest(WebApplicationImpl.java:814)
> at
> com
> .sun
> .jersey
> .server
> .impl
> .application
> .WebApplicationImpl.handleRequest(WebApplicationImpl.java:740)
> at
> com
> .sun
> .jersey
> .server
> .impl
> .application
> .WebApplicationImpl.handleRequest(WebApplicationImpl.java:731)
> at
> com
> .sun
> .jersey.spi.container.servlet.WebComponent.service(WebComponent.java:
> 372)
> at
> com
> .sun
> .jersey
> .spi
> .container.servlet.ServletContainer.service(ServletContainer.java:452)

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

> 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
> .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:128)
> 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:
> 293)
> at
> org
> .apache.coyote.http11.Http11Processor.process(Http11Processor.java:
> 849)
> at
> org.apache.coyote.http11.Http11Protocol
> $Http11ConnectionHandler.process(Http11Protocol.java:583)
> at org.apache.tomcat.util.net.JIoEndpoint
> $Worker.run(JIoEndpoint.java:454)
> at java.lang.Thread.run(Unknown Source)
>
>
>
> Jakub Podlesak wrote:
>>
>>
>> Hi,
>>
>> please see inline...
>>
>> On Tue, Dec 15, 2009 at 04:28:01PM -0800, cgswtsu78 wrote:
>>>
>>> Hello,
>>>
>>> When I perform an HTTP GET request against the below resource
>>> method I
>>> get a
>>> net.sf.json.JSONException: There is a cycle in the hierarchy! (see

>>> below
>>> for
>>> full stack trace). The problem seems to be associated to
>>> returning an
>>> instance of the ImageDetails object after it is retrieved from the
>>> ClientResponse.getEntity method. The ImageDetails object is
>>> successfully
>>> retrieved but when I try to pass that retrieved instance back I
>>> get the
>>> JSONException. When I just create a new version of ImageDetails and

>>> return
>>> that the below method works fine. Any ideas?
>>>
>>> @GET
>>> @Path("/topspamsenderchart")
>>> @Produces("application/json")
>>> public ImageDetails getTopSpamSenderChart() throws Exception{
>>>
>>> Client client = Client.create();
>>> WebResource webResource =
>>> client.resource("http://localhost:8080/ChartWebWiz/jersey/
>>> chartsvcs/");
>>> ClientResponse response =
>>> webResource
>>> .path
>>> ("topspamsenderchart
>>> ").type(MediaType.APPLICATION_XML).post(ClientResponse.class,
>>> chartSpec);
>>>
>>> ImageDetails imgDetails = response.getEntity(ImageDetails.class);
>>> return imgDetails;
>>> }
>>>
>>>
>>> Stack Trace:
>>> net.sf.json.JSONException: There is a cycle in the hierarchy!
>>>
>>> net.sf.json.util.CycleDetectionStrategy
>>> $
>>> StrictCycleDetectionStrategy
>>> .handleRepeatedReferenceAsObject(CycleDetectionStrategy.java:97)
>>> net.sf.json.JSONObject._fromBean(JSONObject.java:859)
>>> net.sf.json.JSONObject.fromObject(JSONObject.java:194)
>>> net.sf.json.JSONObject._processValue(JSONObject.java:2793)
>>> net.sf.json.JSONObject._setInternal(JSONObject.java:2817)
>>> net.sf.json.JSONObject.setValue(JSONObject.java:1527)
>>> net.sf.json.JSONObject._fromBean(JSONObject.java:946)
>>> net.sf.json.JSONObject.fromObject(JSONObject.java:194)
>>> net.sf.json.JSONObject._processValue(JSONObject.java:2793)
>>> net.sf.json.JSONObject._setInternal(JSONObject.java:2817)
>>> net.sf.json.JSONObject.setValue(JSONObject.java:1527)
>>> net.sf.json.JSONObject._fromBean(JSONObject.java:946)
>>> net.sf.json.JSONObject.fromObject(JSONObject.java:194)
>>> net.sf.json.JSONObject._processValue(JSONObject.java:2793)
>>> net.sf.json.JSONObject._setInternal(JSONObject.java:2817)
>>> net.sf.json.JSONObject.setValue(JSONObject.java:1527)
>>> net.sf.json.JSONObject._fromBean(JSONObject.java:946)
>>> net.sf.json.JSONObject.fromObject(JSONObject.java:194)
>>> net.sf.json.JSONObject._processValue(JSONObject.java:2793)
>>> net.sf.json.JSONObject._setInternal(JSONObject.java:2817)
>>> net.sf.json.JSONObject.setValue(JSONObject.java:1527)
>>> net.sf.json.JSONObject._fromBean(JSONObject.java:946)
>>> net.sf.json.JSONObject.fromObject(JSONObject.java:194)
>>> net.sf.json.JSONArray.fromObject(JSONArray.java:194)
>>> net.sf.json.JSONSerializer.toJSON(JSONSerializer.java:113)
>>> net.sf.json.JSONSerializer.toJSON(JSONSerializer.java:84)
>>>
>>> com
>>> .proofpoint
>>> .resources
>>> .chartsvcs.impl.MyEntityProvider.writeTo(MyEntityProvider.java:33)
>>
>> you are apparently using either your own or a 3rd party entity
>> writer,
>> com.proofpoint.resources.chartsvcs.impl.MyEntityProvider.
>> It is hard to diagnose your issue, given that i have no clue what
>> it does.
>>
>> By any chance, have you tried using either Jersey provided writer
>> or the Jackson writer?
>>
>> ~Jakub
>>
>>>
>>> com
>>> .sun
>>> .jersey
>>> .spi.container.ContainerResponse.write(ContainerResponse.java:266)
>>>
>>> com
>>> .sun
>>> .jersey
>>> .server
>>> .impl
>>> .application
>>> .WebApplicationImpl._handleRequest(WebApplicationImpl.java:814)
>>>
>>> com
>>> .sun
>>> .jersey
>>> .server
>>> .impl
>>> .application
>>> .WebApplicationImpl.handleRequest(WebApplicationImpl.java:740)
>>>
>>> com
>>> .sun
>>> .jersey
>>> .server
>>> .impl
>>> .application
>>> .WebApplicationImpl.handleRequest(WebApplicationImpl.java:731)
>>>
>>> com
>>> .sun
>>> .jersey
>>> .spi.container.servlet.WebComponent.service(WebComponent.java:372)
>>>
>>> com
>>> .sun
>>> .jersey
>>> .spi
>>> .container.servlet.ServletContainer.service(ServletContainer.java:
>>> 452)
>>>
>>> com
>>> .sun
>>> .jersey
>>> .spi
>>> .container.servlet.ServletContainer.service(ServletContainer.java:
>>> 633)
>>> javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
>>>
>>> --
>>> View this message in context:
>>>
http://n2.nabble.com/net-sf-json-JSONException-There-is-a-cycle-in-the-h
ierarchy-tp4173118p4173118.html
>>> Sent from the Jersey mailing list archive at Nabble.com.
>>>
>>>
---------------------------------------------------------------------
>>> To unsubscribe, e-mail: [hidden email]
<http://n2.nabble.com/user/SendEmail.jtp?type=node&node=4177396&i=0>
>>> For additional commands, e-mail: [hidden email]
<http://n2.nabble.com/user/SendEmail.jtp?type=node&node=4177396&i=1>
>>>
>>
>> --
>> http://blogs.sun.com/japod
>>
>> ---------------------------------------------------------------------

>> To unsubscribe, e-mail: [hidden email]
<http://n2.nabble.com/user/SendEmail.jtp?type=node&node=4177396&i=2>
>> For additional commands, e-mail: [hidden email]
<http://n2.nabble.com/user/SendEmail.jtp?type=node&node=4177396&i=3>
>>
>>
>>
>
> --
> View this message in context:
http://n2.nabble.com/net-sf-json-JSONException-There-is-a-cycle-in-the-h
ierarchy-tp4173118p4177065.html
> Sent from the Jersey mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
<http://n2.nabble.com/user/SendEmail.jtp?type=node&node=4177396&i=4>
> For additional commands, e-mail: [hidden email]
<http://n2.nabble.com/user/SendEmail.jtp?type=node&node=4177396&i=5>
>



---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
<http://n2.nabble.com/user/SendEmail.jtp?type=node&node=4177396&i=6>
For additional commands, e-mail: [hidden email]
<http://n2.nabble.com/user/SendEmail.jtp?type=node&node=4177396&i=7>




________________________________

View message @
http://n2.nabble.com/net-sf-json-JSONException-There-is-a-cycle-in-the-h
ierarchy-tp4173118p4177396.html
To unsubscribe from Re: net.sf.json.JSONException: There is a cycle in
the hierarchy!, click here
< (link removed)
wb2ludC5jb218NDE3NzA2NXwxMzYyMzc2MzE=> .

 


-- 
View this message in context: http://n2.nabble.com/net-sf-json-JSONException-There-is-a-cycle-in-the-hierarchy-tp4173118p4177455.html
Sent from the Jersey mailing list archive at Nabble.com.