はいくつかの助けを必要としてレンダリング、私は、サーバー側のContoller機能を持っている:再生!フレームワークのサンプルリストはJQuery
public static void getNews(){
List<Thread> threads = Thread.findAll();
renderJSON(threads);
}
とフロントエンドの要求:
<script type="text/javascript">
$.getJSON('@{Application.getNews()}', function(threads) {
var items = [];
$.each(threads, function(title, text) {
items.push("<div>" + text + "</div>");
});
});
</script>
しかし、それは動作しません。コンソールの例外リスト:
Internal Server Error (500) for request GET /application/getnews
Execution exception (In /app/controllers/Application.java around line 43)
IllegalStateException occured : circular reference error Offending field: thre
ads Offending object: preserveType: true, type: class models.Thread, obj: Thr
ead[21]
play.exceptions.JavaExecutionException: circular reference error
Offending field: threads
Offending object: preserveType: true, type: class models.Thread, obj: Thread[2
1]
at play.mvc.ActionInvoker.invoke(ActionInvoker.java:227)
at Invocation.HTTP Request(Play!)
Caused by: java.lang.IllegalStateException: circular reference error
Offending field: threads
Offending object: preserveType: true, type: class models.Thread, obj: Thread[2
1]
at com.google.gson.CircularReferenceException.createDetailedException(Ci
rcularReferenceException.java:43)
at com.google.gson.JsonSerializationVisitor.visitFieldUsingCustomHandler
(JsonSerializationVisitor.java:212)
at com.google.gson.ObjectNavigator.navigateClassFields(ObjectNavigator.j
ava:158)
at com.google.gson.ObjectNavigator.accept(ObjectNavigator.java:131)
at com.google.gson.JsonSerializationVisitor.getJsonElementForChild(JsonS
erializationVisitor.java:147)
at com.google.gson.JsonSerializationVisitor.addAsChildOfObject(JsonSeria
lizationVisitor.java:125)
at com.google.gson.JsonSerializationVisitor.visitObjectField(JsonSeriali
zationVisitor.java:112)
at com.google.gson.ObjectNavigator.navigateClassFields(ObjectNavigator.j
ava:164)
at com.google.gson.ObjectNavigator.accept(ObjectNavigator.java:131)
at com.google.gson.JsonSerializationContextDefault.serialize(JsonSeriali
zationContextDefault.java:56)
at com.google.gson.JsonSerializationContextDefault.serialize(JsonSeriali
zationContextDefault.java:49)
at com.google.gson.DefaultTypeAdapters$CollectionTypeAdapter.serialize(D
efaultTypeAdapters.java:528)
at com.google.gson.DefaultTypeAdapters$CollectionTypeAdapter.serialize(D
efaultTypeAdapters.java:510)
at com.google.gson.JsonSerializationVisitor.findAndInvokeCustomSerialize
r(JsonSerializationVisitor.java:184)
at com.google.gson.JsonSerializationVisitor.visitUsingCustomHandler(Json
SerializationVisitor.java:160)
at com.google.gson.ObjectNavigator.accept(ObjectNavigator.java:106)
at com.google.gson.JsonSerializationContextDefault.serialize(JsonSeriali
zationContextDefault.java:56)
at com.google.gson.Gson.toJsonTree(Gson.java:233)
at com.google.gson.Gson.toJson(Gson.java:273)
at com.google.gson.Gson.toJson(Gson.java:253)
at play.mvc.results.RenderJson.<init>(RenderJson.java:20)
at play.mvc.Controller.renderJSON(Controller.java:325)
at controllers.Application.getNews(Application.java:43)
at play.mvc.ActionInvoker.invokeWithContinuation(ActionInvoker.java:540)
at play.mvc.ActionInvoker.invoke(ActionInvoker.java:498)
at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:474)
at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:469)
at play.mvc.ActionInvoker.invoke(ActionInvoker.java:157)
... 1 more
Caused by: com.google.gson.CircularReferenceException: circular reference error
at com.google.gson.JsonSerializationVisitor.start(JsonSerializationVisit
or.java:56)
at com.google.gson.ObjectNavigator.accept(ObjectNavigator.java:114)
at com.google.gson.JsonSerializationContextDefault.serialize(JsonSeriali
zationContextDefault.java:56)
at com.google.gson.JsonSerializationContextDefault.serialize(JsonSeriali
zationContextDefault.java:49)
at com.google.gson.DefaultTypeAdapters$CollectionTypeAdapter.serialize(D
efaultTypeAdapters.java:528)
at com.google.gson.DefaultTypeAdapters$CollectionTypeAdapter.serialize(D
efaultTypeAdapters.java:510)
at com.google.gson.JsonSerializationVisitor.findAndInvokeCustomSerialize
r(JsonSerializationVisitor.java:184)
at com.google.gson.JsonSerializationVisitor.visitFieldUsingCustomHandler
(JsonSerializationVisitor.java:203)
... 27 more