Note that there are some explanatory texts on larger screens.

plurals
  1. POStrange ExecutionException when doing POST with JSON
    primarykey
    data
    text
    <p>I have this method:</p> <pre><code>/** * POST */ public static void create(String body) { Logger.info("APPOINTMENT create - json string: %s", body); Appointment appointment = null; try { appointment = new Gson().fromJson(body, Appointment.class); //services are detached, re-take them from db List&lt;Service&gt; refreshedServices = new ArrayList&lt;Service&gt;(); for (final Service ser : appointment.services) { Service service = Service.findById(ser.id); refreshedServices.add(service); } appointment.services = refreshedServices; appointment.save(); appointment.refresh(); Logger.info("services refreshed"); } catch (Exception ex) { Logger .info( "An error has occured when trying to create an APPOINTMENT %s", ex); response.status = Http.StatusCode.INTERNAL_ERROR; renderJSON(new StatusMessage( "An internal error has occured. Please try again later.")); } renderJSON(appointment); } </code></pre> <p>I'm testing it like this:</p> <pre><code>public void createAppointment(final Contact contact, final List&lt;Service&gt; services) throws Exception { Appointment app = new Appointment(); app.userUid = "cristi-uid"; app.name = "app1"; app.contact = contact; String serviceAsJson = "{\"userUid\":\"cristi-uid\",\"name\":\"app1\",\"allDay\":false,\"contact\":{\"id\":"+contact.id+"},\"services\":[{\"id\":\""+services.get(0).getId()+"\"},{\"id\":\""+services.get(1).getId()+"\"}]}"; Response response = POST("/appointment/create", "application/json", serviceAsJson); Logger.info("POST was done"); Appointment appReturned = new Gson().fromJson(response.out.toString(), Appointment.class); Logger.info("appointment create response: %s", response.out.toString()); assertIsOk(response); assertEquals(appReturned.name, app.name); } </code></pre> <p>Well, the issue is that it is throwing this exception:</p> <pre><code>java.lang.RuntimeException: java.util.concurrent.ExecutionException: play.exceptions.JavaExecutionException at play.test.FunctionalTest.makeRequest(FunctionalTest.java:304) at play.test.FunctionalTest.makeRequest(FunctionalTest.java:310) at play.test.FunctionalTest.POST(FunctionalTest.java:152) at play.test.FunctionalTest.POST(FunctionalTest.java:120) at play.test.FunctionalTest.POST(FunctionalTest.java:116) at AppointmentsTest.createAppointment(AppointmentsTest.java:61) </code></pre> <p>and I am unable to find out why.</p> <p>It prints out <code>Logger.info("services refreshed");</code> after that it is throwing the exception...</p> <p>Do you guys see anything wrong with this test POST?</p> <p><strong>UPDATE</strong>: Seems that the issues comes from trying to render the <code>appointment</code> as JSON:</p> <pre><code>Caused by: java.lang.StackOverflowError at java.util.LinkedHashMap$LinkedHashIterator.(LinkedHashMap.java:345) at java.util.LinkedHashMap$LinkedHashIterator.(LinkedHashMap.java:345) at java.util.LinkedHashMap$ValueIterator.(LinkedHashMap.java:387) at java.util.LinkedHashMap$ValueIterator.(LinkedHashMap.java:387) at java.util.LinkedHashMap.newValueIterator(LinkedHashMap.java:397) at java.util.HashMap$Values.iterator(HashMap.java:910) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.write(ReflectiveTypeAdapterFactory.java:192) at com.google.gson.Gson$FutureTypeAdapter.write(Gson.java:879) at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:68) at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(CollectionTypeAdapterFactory.java:96) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload