0

i have a model with parent-child structure when i set parent model the following exception occures:

com.google.gwt.core.client.JavaScriptException: (InternalError) : too much recursion
at com.google.gwt.lang.Exceptions.wrap(Exceptions.java:36)

i have traced generated java class for my Model when toJson called it tries to call toJson for parent property and in toJson of parent property it tries to call toJson of children list and after some calls throws too much recursion.

how can i solve that? is there any Annotation for that?

RockAndRoll
  • 2,247
  • 2
  • 16
  • 35
Saeed Shahsavan
  • 35
  • 1
  • 10

1 Answers1

1

You should probably annotate the toJson method with @JsonIgnore or make it transient. It is getting to a circular reference when trying to serialize the objects.

You can convert an entity to json using the JsonEncoder/Decoder support in resty.You probably want to move this functionality out of your entity bean and into another class or you will have to annotate it with @JsonIgnore or make the method transient.

https://resty-gwt.github.io/documentation/restygwt-user-guide.html

See JSON Encoder/Decoders

Chris Hinshaw
  • 6,967
  • 2
  • 39
  • 65
  • i dont want to ignor that property it works with gwittir and also it works with RequestFacroty how they handle this type of problems? – Saeed Shahsavan Dec 03 '15 at 13:16
  • Is your method actually going through and parsing the entity to convert it to a json object? How are you converting it to json in the toJson method? A code sample of the entity and an example of the toJson method would be very helpful. I think you can keep the functionality but need to move it out of the entity. If you don't need to send the entire object in json containing a field that also encases the json then you should move the toJson functionality out of the entity. Then use a Codec to convert it to json and then use it for gwittr. If you have @JsonIgnore or transient it just won't send – Chris Hinshaw Dec 03 '15 at 18:03
  • the entity over the wire. If the method is actually creating the json dynamically then you want to use transient or jsonIgnore. The toJson method will still work as expected but the field won't be serialized when sending the method to the server. You should probably still be able to call the method and get the String json or JsonObject from the toJson method. – Chris Hinshaw Dec 03 '15 at 18:05
  • do you know how gwt RequestFactory handles these type of problems??? i dont know, but i think there is a way to handle these type of problems – Saeed Shahsavan Dec 05 '15 at 08:38