### Question:
JsrJsonpProvider implements MessageBodyReader<JsonStructure>, MessageBodyWriter<JsonStructure> { @Override public void writeTo(JsonStructure t, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException { if (entityStream == null) { throw new IOException("Initialized OutputStream should be provided"); } try (JsonWriter writer = Json.createWriter(entityStream)) { writer.write(t); } }  @Override boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType); @Override long getSize(JsonStructure t, Class<?> type, Type genericType, Annotation[] annotations,
        MediaType mediaType); @Override void writeTo(JsonStructure t, Class<?> type, Type genericType, Annotation[] annotations,
        MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream); @Override boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType); @Override JsonStructure readFrom(Class<JsonStructure> type, Type genericType, Annotation[] annotations,
        MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream);  }### Answer:
@Test(expected = IOException.class) public void testWriteWithNullStream() throws Exception { final JsonObject obj = Json.createObjectBuilder() .add("firstName", "Tom") .add("lastName", "Tommyknocker") .build(); provider.writeTo(obj, JsonObject.class, null, null, null, null, null); }
@Test public void testWriteJsonObject() throws Exception { final JsonObject obj = Json.createObjectBuilder() .add("firstName", "Tom") .add("lastName", "Tommyknocker") .build(); final ByteArrayOutputStream out = new ByteArrayOutputStream(); provider.writeTo(obj, JsonStructure.class, null, null, null, null, out); out.close(); assertThat(new String(out.toByteArray()), equalTo("{\"firstName\":\"Tom\",\"lastName\":\"Tommyknocker\"}")); }
@Test public void testWriteJsonArray() throws Exception { final JsonArray obj = Json.createArrayBuilder() .add( Json.createObjectBuilder() .add("firstName", "Tom") .add("lastName", "Tommyknocker") ) .add( Json.createObjectBuilder() .add("firstName", "Bob") .add("lastName", "Bobbyknocker") ) .build(); final ByteArrayOutputStream out = new ByteArrayOutputStream(); provider.writeTo(obj, JsonStructure.class, null, null, null, null, out); out.close(); assertThat(new String(out.toByteArray()), equalTo("[{\"firstName\":\"Tom\",\"lastName\":\"Tommyknocker\"}," + "{\"firstName\":\"Bob\",\"lastName\":\"Bobbyknocker\"}]")); }