Как сериализовать java.util.List <E> в Json с помощью библиотеки Gson?

В моем сервлете у меня есть следующий код:

<code>    response.setContentType("application/json");//set json content type
    PrintWriter out = response.getWriter();

   EntityManagerFactory emf=Persistence.createEntityManagerFactory("webPU");
   GpsJpaController gjc=new GpsJpaController(emf);    
   java.util.List<Gps> listGps=gjc.findGpsEntities();//retrieve the list of GPS from DB 

   Gson gson=new Gson();
   String json=gson.toJson(listGps); //convert List<Gps> to json
   out.println(json);
</code>

ответ возвращается из ajax с этим кодом:

<code>$.ajax({ 
           type: "GET", 
           url: "getInfoGeoActive",
           dataType: 'json',
           error: function(xhr, ajaxOptions, thrownError){ $("#content").empty().append("* Error from server cause: "+thrownError).addClass("error"); } ,
           success:function(data){$("#content").empty().append(data);}
             });
</code>

когда я запускаю код, я все еще получаю следующую ошибку (из ajax):

<code>  Error from server cause:Internal Servlet Error
</code>

Я также пытался отобразить сериализованный объектList<Gps> в той же странице Java без AJAX, а именно:

<code>EntityManagerFactory emf=Persistence.createEntityManagerFactory("JavaApplication21PU");
        GpsJpaController gjc=new GpsJpaController(emf);
        java.util.List<Gps> listGps=gjc.findGpsEntities();

        Gson gson=new Gson();
        String json=gson.toJson(listGps);

        System.out.println(json);
</code>

Я получаю эту ошибку:

<code>Exception in thread "main" java.lang.StackOverflowError
    at java.lang.StrictMath.floorOrCeil(StrictMath.java:355)
    at java.lang.StrictMath.floor(StrictMath.java:340)
    at java.lang.Math.floor(Math.java:424)
    at sun.misc.FloatingDecimal.dtoa(FloatingDecimal.java:620)
    at sun.misc.FloatingDecimal.<init>(FloatingDecimal.java:459)
    at java.lang.Double.toString(Double.java:196)
    at java.lang.Double.toString(Double.java:633)
    at com.google.gson.stream.JsonWriter.value(JsonWriter.java:441)
    at com.google.gson.Gson$4.write(Gson.java:270)
    at com.google.gson.Gson$4.write(Gson.java:255)
</code>

Пожалуйста помоги!

EDIT: окончательное решение этой проблемы

Ответы на вопрос(2)

Ваш ответ на вопрос