I try to send data from the servlet in JSON in JavaScript using the response.getWriter().write(JSON) method, but I get into an infinite loop.

  String JSON = builder.toJson(Complete_map); response.setContentType("text/plain"); response.getWriter().write(JSON); 

Complete map - HashMap of string values. I use GSON library. But no matter what I gave, there is always an endless cycle.

  function show_Value() { function MapObject(name,value,mutter) { this.name= name; this.value = value; this.mutter = mutter; } $.ajax({ url:'show_Registers', success : function(responseText) { var map = String.valueOf(responseText); var p = JSON.stringify(map); $('#MyFuckingMap').text(p); setTimeout(500,show_Value()); } }); } 

And this thing happens only in Google Chrome , Opera and IE , the data in ajax , apparently do not come.

    1 answer 1

    This is because your objects have a cyclic circularity. Note that you cannot serialize objects with circular references, as this will result in infinite recursion.

     class BagOfPrimitives { private int value1 = 1; private String value2 = "abc"; private transient int value3 = 3; BagOfPrimitives() { // no-args constructor } } (Serialization) BagOfPrimitives obj = new BagOfPrimitives(); Gson gson = new Gson(); String json = gson.toJson(obj); ==> json is {"value1":1,"value2":"abc"}