users@jersey.java.net

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

From: Jakub Podlesak <Jakub.Podlesak_at_Sun.COM>
Date: Wed, 16 Dec 2009 15:29:44 +0100

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-hierarchy-tp4173118p4173118.html
> Sent from the Jersey mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>

-- 
http://blogs.sun.com/japod