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)
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.