@Override
    public void writeTo(
            T obj, Class<?> cls, Type type, Annotation[] anns, MediaType mt,
            MultivaluedMap<String, Object> headers, OutputStream os)
            throws IOException,
            WebApplicationException {
        DataFormat format = getValidDataFormat(mt);
        try {
            format.marshal(null, obj, os);
        } catch (Exception ex) {
            throw new InternalServerErrorException(ex);
        }

    }
@Test
    public void testWriteTo() throws Exception {
        DataFormatProvider<Book> p = new DataFormatProvider<>();
        p.setFormat("text/plain", new TestDataFormat());

        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        p.writeTo(new Book("dataformat"), Book.class, Book.class, new Annotation[] {},
                MediaType.TEXT_PLAIN_TYPE, new MetadataMap<String, Object>(), bos);
        assertEquals("dataformat", bos.toString());
    }