@Test public void testWriteError() throws Exception { JsonErrorResponseWriter writer = new JsonErrorResponseWriter(); String json = writer.getJsonError(new ODataServerException(EDM_ERROR, "EDM error")); assertEquals(prettyPrintJson(readContent(EXPECTED_ERROR_RESPONSE_PATH)), prettyPrintJson(json)); }
public String getJsonError(ODataException exception) throws ODataRenderException { checkNotNull(exception); LOG.debug("Start building Json error document"); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); try { JsonGenerator jsonGenerator = JSON_FACTORY.createGenerator(outputStream, JsonEncoding.UTF8); jsonGenerator.writeStartObject(); jsonGenerator.writeObjectFieldStart(ERROR); jsonGenerator.writeStringField(CODE, String.valueOf(exception.getCode().getCode())); jsonGenerator.writeStringField(MESSAGE, String.valueOf(exception.getMessage())); if (exception.getTarget() != null) { jsonGenerator.writeStringField(TARGET, String.valueOf(exception.getTarget()).replace("\"", "'")); } jsonGenerator.writeEndObject(); jsonGenerator.close(); return outputStream.toString(); } catch (IOException e) { LOG.error("Not possible to write error JSON."); throw new ODataRenderException("Not possible to write error JSON: ", e); } }
JsonErrorResponseWriter { public String getJsonError(ODataException exception) throws ODataRenderException { checkNotNull(exception); LOG.debug("Start building Json error document"); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); try { JsonGenerator jsonGenerator = JSON_FACTORY.createGenerator(outputStream, JsonEncoding.UTF8); jsonGenerator.writeStartObject(); jsonGenerator.writeObjectFieldStart(ERROR); jsonGenerator.writeStringField(CODE, String.valueOf(exception.getCode().getCode())); jsonGenerator.writeStringField(MESSAGE, String.valueOf(exception.getMessage())); if (exception.getTarget() != null) { jsonGenerator.writeStringField(TARGET, String.valueOf(exception.getTarget()).replace("\"", "'")); } jsonGenerator.writeEndObject(); jsonGenerator.close(); return outputStream.toString(); } catch (IOException e) { LOG.error("Not possible to write error JSON."); throw new ODataRenderException("Not possible to write error JSON: ", e); } } }
JsonErrorResponseWriter { public String getJsonError(ODataException exception) throws ODataRenderException { checkNotNull(exception); LOG.debug("Start building Json error document"); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); try { JsonGenerator jsonGenerator = JSON_FACTORY.createGenerator(outputStream, JsonEncoding.UTF8); jsonGenerator.writeStartObject(); jsonGenerator.writeObjectFieldStart(ERROR); jsonGenerator.writeStringField(CODE, String.valueOf(exception.getCode().getCode())); jsonGenerator.writeStringField(MESSAGE, String.valueOf(exception.getMessage())); if (exception.getTarget() != null) { jsonGenerator.writeStringField(TARGET, String.valueOf(exception.getTarget()).replace("\"", "'")); } jsonGenerator.writeEndObject(); jsonGenerator.close(); return outputStream.toString(); } catch (IOException e) { LOG.error("Not possible to write error JSON."); throw new ODataRenderException("Not possible to write error JSON: ", e); } }  }
JsonErrorResponseWriter { public String getJsonError(ODataException exception) throws ODataRenderException { checkNotNull(exception); LOG.debug("Start building Json error document"); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); try { JsonGenerator jsonGenerator = JSON_FACTORY.createGenerator(outputStream, JsonEncoding.UTF8); jsonGenerator.writeStartObject(); jsonGenerator.writeObjectFieldStart(ERROR); jsonGenerator.writeStringField(CODE, String.valueOf(exception.getCode().getCode())); jsonGenerator.writeStringField(MESSAGE, String.valueOf(exception.getMessage())); if (exception.getTarget() != null) { jsonGenerator.writeStringField(TARGET, String.valueOf(exception.getTarget()).replace("\"", "'")); } jsonGenerator.writeEndObject(); jsonGenerator.close(); return outputStream.toString(); } catch (IOException e) { LOG.error("Not possible to write error JSON."); throw new ODataRenderException("Not possible to write error JSON: ", e); } }  String getJsonError(ODataException exception); }
JsonErrorResponseWriter { public String getJsonError(ODataException exception) throws ODataRenderException { checkNotNull(exception); LOG.debug("Start building Json error document"); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); try { JsonGenerator jsonGenerator = JSON_FACTORY.createGenerator(outputStream, JsonEncoding.UTF8); jsonGenerator.writeStartObject(); jsonGenerator.writeObjectFieldStart(ERROR); jsonGenerator.writeStringField(CODE, String.valueOf(exception.getCode().getCode())); jsonGenerator.writeStringField(MESSAGE, String.valueOf(exception.getMessage())); if (exception.getTarget() != null) { jsonGenerator.writeStringField(TARGET, String.valueOf(exception.getTarget()).replace("\"", "'")); } jsonGenerator.writeEndObject(); jsonGenerator.close(); return outputStream.toString(); } catch (IOException e) { LOG.error("Not possible to write error JSON."); throw new ODataRenderException("Not possible to write error JSON: ", e); } }  String getJsonError(ODataException exception);  }