2

I have a java ee application that uses jax-rs. But when i return a boolean in a call that returns json, it gives a 500 error.

    @GET
    @Path("/test")
    @Produces("application/json")
    public boolean test() {
        return true;
    }

The above code will give this generic error message: The server encountered an internal error that prevented it from fulfilling this request.

If i remove the @Produces("application/json") it does work but returns 'text/plain'.

Lieke
  • 181
  • 1
  • 12

1 Answers1

2

JSON consists of key:value pairs. So you cannot return a simple boolean, because what should be the name of the corresponding key ?

So either return a Map<String, Boolean> or a boolean[]

Svetlin Zarev
  • 14,713
  • 4
  • 53
  • 82
  • 1
    I still got a 500 when i tried to return a map or a boolean[] but i made a custom class to return the value.Which worked.Thanks! – Lieke Mar 10 '17 at 13:26
  • I also had to add the `jersey-media-json-jackson` depency to make it work with my custom class. – Lieke Mar 10 '17 at 13:44