2012-10-07 5 views
0

안녕하세요,JSON으로 순환

나는 Json 목록을 변환하려는 서블릿이 있습니다.

SEVERE: Servlet.service() para servlet reunionServlet lanzó excepción net.sf.json.JSONException: There is a cycle in the hierarchy! at net.sf.json.util.CycleDetectionStrategy$StrictCycleDetectionStrategy.handleRepeatedReferenceAsObject(CycleDetectionStrategy.java:97) at net.sf.json.JSONObject._fromBean(JSONObject.java:857) at net.sf.json.JSONObject.fromObject(JSONObject.java:192) at net.sf.json.JSONObject._processValue(JSONObject.java:2774) at net.sf.json.JSONObject._setInternal(JSONObject.java:2798) at net.sf.json.JSONObject.setValue(JSONObject.java:1507) at net.sf.json.JSONObject._fromBean(JSONObject.java:940) at net.sf.json.JSONObject.fromObject(JSONObject.java:192) at net.sf.json.JSONArray._processValue(JSONArray.java:2557) at net.sf.json.JSONArray.processValue(JSONArray.java:2588) at net.sf.json.JSONArray.addValue(JSONArray.java:2575) at net.sf.json.JSONArray._fromCollection(JSONArray.java:1082) at net.sf.json.JSONArray.fromObject(JSONArray.java:145) at net.sf.json.JSONObject._processValue(JSONObject.java:2749) at net.sf.json.JSONObject._setInternal(JSONObject.java:2798) at net.sf.json.JSONObject.setValue(JSONObject.java:1507) at net.sf.json.JSONObject._fromBean(JSONObject.java:940) at net.sf.json.JSONObject.fromObject(JSONObject.java:192) at net.sf.json.JSONObject._processValue(JSONObject.java:2774) at net.sf.json.JSONObject._setInternal(JSONObject.java:2798) at net.sf.json.JSONObject.setValue(JSONObject.java:1507) at net.sf.json.JSONObject._fromBean(JSONObject.java:940) at net.sf.json.JSONObject.fromObject(JSONObject.java:192) at net.sf.json.JSONObject._processValue(JSONObject.java:2774) at net.sf.json.JSONObject._setInternal(JSONObject.java:2798) at net.sf.json.JSONObject.setValue(JSONObject.java:1507) at net.sf.json.JSONObject._fromBean(JSONObject.java:940) at net.sf.json.JSONObject.fromObject(JSONObject.java:192) at net.sf.json.JSONObject._processValue(JSONObject.java:2774) at net.sf.json.JSONObject._setInternal(JSONObject.java:2798) at net.sf.json.JSONObject.setValue(JSONObject.java:1507) at net.sf.json.JSONObject._fromBean(JSONObject.java:940) at net.sf.json.JSONObject.fromObject(JSONObject.java:192) at net.sf.json.JSONArray._processValue(JSONArray.java:2557) at net.sf.json.JSONArray.processValue(JSONArray.java:2588) at net.sf.json.JSONArray.addValue(JSONArray.java:2575) at net.sf.json.JSONArray._fromCollection(JSONArray.java:1082) at net.sf.json.JSONArray.fromObject(JSONArray.java:145) at net.sf.json.JSONArray.fromObject(JSONArray.java:127) at servlet.ReunionServlet.doPost(ReunionServlet.java:176) at javax.servlet.http.HttpServlet.service(HttpServlet.java:641) at javax.servlet.http.HttpServlet.service(HttpServlet.java:722) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:164) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:562) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:395) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:250) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:166) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source)

가 수행 어디 있는지 알고

내가 코드를 다음과 같은 오류를 실행하면

내가 형 재회의 객체를 저장 lista_reunion에 다음 코드를

List<Reunion> lista_reuniones = facadeReunion.getServidoresTareas(); 

     JSONArray mJSONArray = JSONArray.fromObject(lista_reuniones); 

를 사용 문제? 그것이 도움이 있다면 다음과 같이 데이터베이스의도이다 :

enter image description here

들으

답변

4

Organizacion 재회에이 일대의 관계이다. 그것은 양방향 관계가 아닌 경우이 유형의 예외를 유발할 수있는 순환 참조를 형성 할 수 있습니다.

Jackson을 사용하여 bean을 직렬화 할 때 동일한 유형의 문제점이있었습니다. 당시 나는 내 프로젝트에서 Hibernate를 사용하고 있었다.

@ JacksonManagedReference 및 @JsonBackReference 주석을 직렬화하고 사용하기 위해 Jackson을 사용하면이 문제를 피할 수 있습니다.

0

내 엔티티의 일부 속성이 지연 (JPA)으로 인해 문제가 발생했습니다.

내가이 명령과 함께 jsonConfig를 포함 해결하려면

JsonConfig jsonConfig = new JsonConfig(); 
jsonConfig.setExcludes(new String[]{"files", "createdBy", "lastUpdatedBy"}); 
jsonConfig.setIgnoreDefaultExcludes(false); 
jsonConfig.setCycleDetectionStrategy(CycleDetectionStrategy.LENIENT); 

JSONObject jsonObject = JSONObject.fromObject(obj, config); 

이 나에게 잘 작동합니다. ;-)

+0

이것은 나를 위해 일했다. 감사!! –