SAXSourceEntityProvider implements EntityProvider<SAXSource> { @Override public void writeTo(SAXSource saxSource, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException { StreamResult streamResult = new StreamResult(entityStream); try { TransformerFactory factory = createFeaturedTransformerFactory(); factory.newTransformer().transform(saxSource, streamResult); } catch (TransformerException | TransformerFactoryConfigurationError e) { throw new IOException(String.format("Can't write to output stream, %s", e)); } }  @Override boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType); @Override SAXSource readFrom(Class<SAXSource> type,
                              Type genericType,
                              Annotation[] annotations,
                              MediaType mediaType,
                              MultivaluedMap<String, String> httpHeaders,
                              InputStream entityStream); @Override long getSize(SAXSource t, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType); @Override boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType); @Override void writeTo(SAXSource saxSource,
                        Class<?> type,
                        Type genericType,
                        Annotation[] annotations,
                        MediaType mediaType,
                        MultivaluedMap<String, Object> httpHeaders,
                        OutputStream entityStream);  }
@Test public void writesSAXSourceToOutputStream() throws Exception { ByteArrayOutputStream out = new ByteArrayOutputStream(); saxSourceEntityProvider.writeTo(new SAXSource(new InputSource(new ByteArrayInputStream(TEST_XML_CONTENT_BYTES))), SAXSource.class, null, null, APPLICATION_XML_TYPE, null, out); Document serializedDocument = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new ByteArrayInputStream(out.toByteArray())); assertThatXmlDocumentContainsAllExpectedNodes(serializedDocument); }