package io.limberest.json;

import javax.ws.rs.Consumes;
import javax.ws.rs.Produces;

import org.json.JSONObject;

import io.limberest.service.http.RestService;

@Consumes("application/json")
@Produces("application/json")
public abstract class JsonRestService extends RestService<JSONObject> {

    @Override
    public JSONObject getBody(String text) {
        return new JsonObject(text);
    }

    @Override
    public String getText(JSONObject json, int prettyIndent) {
        return json.toString(prettyIndent);
    }
}

@@ -104,16 +104,93 @@
 JSON
-Object;%0A
+Exception;%0Aimport org.json.JSONObject;%0A%0Aimport io.limberest.service.ServiceException;
 %0Aimp
@@ -231,16 +231,57 @@
 Service;
+%0Aimport io.limberest.service.http.Status;
 %0A%0A@Consu
@@ -468,46 +468,220 @@
 xt) 
-%7B%0A        return new JsonObject(text);
+throws ServiceException %7B%0A        try %7B%0A            return new JsonObject(text);%0A        %7D%0A        catch (JSONException ex) %7B%0A            throw new ServiceException(Status.BAD_REQUEST, ex.getMessage());%0A        %7D
 %0A   

Handle malformed JSON.