@Test public void quotes_are_escaped() { var json = ErrorResponse.asErrorJson("Message \" with \" embedded quotes."); assertEquals("{\"error\":\"Message \\\" with \\\" embedded quotes.\"}", json); }
static String asErrorJson(String message) { try { return objectMapper.writeValueAsString(Map.of("error", message)); } catch (JsonProcessingException e) { log.log(WARNING, "Could not encode error message to json:", e); return "Could not encode error message to json, check the log for details."; } }
ErrorResponse extends JsonResponse { static String asErrorJson(String message) { try { return objectMapper.writeValueAsString(Map.of("error", message)); } catch (JsonProcessingException e) { log.log(WARNING, "Could not encode error message to json:", e); return "Could not encode error message to json, check the log for details."; } } }
ErrorResponse extends JsonResponse { static String asErrorJson(String message) { try { return objectMapper.writeValueAsString(Map.of("error", message)); } catch (JsonProcessingException e) { log.log(WARNING, "Could not encode error message to json:", e); return "Could not encode error message to json, check the log for details."; } } ErrorResponse(int code, String message); }
ErrorResponse extends JsonResponse { static String asErrorJson(String message) { try { return objectMapper.writeValueAsString(Map.of("error", message)); } catch (JsonProcessingException e) { log.log(WARNING, "Could not encode error message to json:", e); return "Could not encode error message to json, check the log for details."; } } ErrorResponse(int code, String message);  }
ErrorResponse extends JsonResponse { static String asErrorJson(String message) { try { return objectMapper.writeValueAsString(Map.of("error", message)); } catch (JsonProcessingException e) { log.log(WARNING, "Could not encode error message to json:", e); return "Could not encode error message to json, check the log for details."; } } ErrorResponse(int code, String message);   }