@Test public void testWriteErrorMessageHeader() { ErrorMessageHeader errorMessageHeader = new ErrorMessageHeader("microservice-1-uri", 1456485443905L, 404, "Service unavailable"); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); new ErrorMessageHeaderWriter().writeObject(errorMessageHeader, outputStream); String jsonResult = outputStream.toString(); JsonFluentAssert actualJson = JsonFluentAssert.assertThatJson(jsonResult); InputStream expectedJson = getClass().getClassLoader().getResourceAsStream("errors/serialization/errormessageheader.json"); String expectedJSON = null; try { expectedJSON = ReadFile.getFileContents(expectedJson).toString(); } catch (IOException e) { e.printStackTrace(); } actualJson.hasSameStructureAs(expectedJSON); actualJson.isEqualTo(expectedJSON); }
@Override public void writeObject(ErrorMessageHeader errorMessageHeader, OutputStream outputStream) throws ErrorMessageHeaderSerializationException { ObjectMapper mapper = new ObjectMapper(); try { mapper.writeValue(outputStream, errorMessageHeader); } catch (Exception e) { String message = "Could not serialize a " + ErrorMessageHeader.class.getName() + " object. Cause: " + e.getMessage(); throw new ErrorMessageHeaderSerializationException(message, e); } }
ErrorMessageHeaderWriter implements SerializationWriter<ErrorMessageHeader> { @Override public void writeObject(ErrorMessageHeader errorMessageHeader, OutputStream outputStream) throws ErrorMessageHeaderSerializationException { ObjectMapper mapper = new ObjectMapper(); try { mapper.writeValue(outputStream, errorMessageHeader); } catch (Exception e) { String message = "Could not serialize a " + ErrorMessageHeader.class.getName() + " object. Cause: " + e.getMessage(); throw new ErrorMessageHeaderSerializationException(message, e); } } }
ErrorMessageHeaderWriter implements SerializationWriter<ErrorMessageHeader> { @Override public void writeObject(ErrorMessageHeader errorMessageHeader, OutputStream outputStream) throws ErrorMessageHeaderSerializationException { ObjectMapper mapper = new ObjectMapper(); try { mapper.writeValue(outputStream, errorMessageHeader); } catch (Exception e) { String message = "Could not serialize a " + ErrorMessageHeader.class.getName() + " object. Cause: " + e.getMessage(); throw new ErrorMessageHeaderSerializationException(message, e); } }  }
ErrorMessageHeaderWriter implements SerializationWriter<ErrorMessageHeader> { @Override public void writeObject(ErrorMessageHeader errorMessageHeader, OutputStream outputStream) throws ErrorMessageHeaderSerializationException { ObjectMapper mapper = new ObjectMapper(); try { mapper.writeValue(outputStream, errorMessageHeader); } catch (Exception e) { String message = "Could not serialize a " + ErrorMessageHeader.class.getName() + " object. Cause: " + e.getMessage(); throw new ErrorMessageHeaderSerializationException(message, e); } }  @Override void writeObject(ErrorMessageHeader errorMessageHeader, OutputStream outputStream); }
ErrorMessageHeaderWriter implements SerializationWriter<ErrorMessageHeader> { @Override public void writeObject(ErrorMessageHeader errorMessageHeader, OutputStream outputStream) throws ErrorMessageHeaderSerializationException { ObjectMapper mapper = new ObjectMapper(); try { mapper.writeValue(outputStream, errorMessageHeader); } catch (Exception e) { String message = "Could not serialize a " + ErrorMessageHeader.class.getName() + " object. Cause: " + e.getMessage(); throw new ErrorMessageHeaderSerializationException(message, e); } }  @Override void writeObject(ErrorMessageHeader errorMessageHeader, OutputStream outputStream);  }