### Question:
JAXBElementProvider extends AbstractJAXBProvider<T> { protected void marshal(Object obj, Class<?> cls, Type genericType, String enc, OutputStream os, MediaType mt) throws Exception { marshal(obj, cls, genericType, enc, os, mt, new Annotation[]{}); } JAXBElementProvider(); void setXmlResourceOffset(String value); void setNamespacePrefixes(Map<String, String> prefixes); @Context void setMessageContext(MessageContext mc); void setMarshallerProperties(Map<String, Object> marshallProperties); void setSchemaLocation(String schemaLocation); T readFrom(Class<T> type, Type genericType, Annotation[] anns, MediaType mt,
        MultivaluedMap<String, String> headers, InputStream is); void writeTo(T obj, Class<?> cls, Type genericType, Annotation[] anns,
        MediaType m, MultivaluedMap<String, Object> headers, OutputStream os); void setXmlPiPropertyName(String xmlPiPropertyName);  }### Answer:
@Test public void testExtraClassWithoutSingleContext() throws Exception { ClassResourceInfo cri = ResourceUtils.createClassResourceInfo(BookStore.class, BookStore.class, true, true); JAXBElementProvider<SuperBook> provider = new JAXBElementProvider<>(); provider.setExtraClass(new Class[]{SuperBook.class}); provider.init(Collections.singletonList(cri)); JAXBContext bookContext = provider.getJAXBContext(Book.class, Book.class); ByteArrayOutputStream os = new ByteArrayOutputStream(); bookContext.createMarshaller().marshal(new SuperBook("name", 1L, 2L), os); SuperBook book = (SuperBook)bookContext.createUnmarshaller() .unmarshal(new ByteArrayInputStream(os.toByteArray())); assertEquals(2L, book.getSuperId()); }
@Test public void testGenericsAndSingleContext2() throws Exception { ClassResourceInfo cri = ResourceUtils.createClassResourceInfo(XmlListResource.class, XmlListResource.class, true, true); JAXBElementProvider<?> provider = new JAXBElementProvider<>(); provider.setSingleJaxbContext(true); provider.init(Collections.singletonList(cri)); List<org.apache.cxf.jaxrs.fortest.jaxb.SuperBook> list = new ArrayList<>(); for (int i = 0; i < 10; i++) { org.apache.cxf.jaxrs.fortest.jaxb.SuperBook o = new org.apache.cxf.jaxrs.fortest.jaxb.SuperBook(); o.setName("name #" + i); list.add(o); } XmlList<org.apache.cxf.jaxrs.fortest.jaxb.SuperBook> xmlList = new XmlList<>(list); Method m = XmlListResource.class.getMethod("testJaxb2", new Class[]{}); JAXBContext context = provider.getJAXBContext(m.getReturnType(), m.getGenericReturnType()); ByteArrayOutputStream os = new ByteArrayOutputStream(); context.createMarshaller().marshal(xmlList, os); @SuppressWarnings("unchecked") XmlList<org.apache.cxf.jaxrs.fortest.jaxb.SuperBook> list2 = (XmlList<org.apache.cxf.jaxrs.fortest.jaxb.SuperBook>)context.createUnmarshaller() .unmarshal(new ByteArrayInputStream(os.toByteArray())); List<org.apache.cxf.jaxrs.fortest.jaxb.SuperBook> actualList = list2.getList(); assertEquals(10, actualList.size()); for (int i = 0; i < 10; i++) { org.apache.cxf.jaxrs.fortest.jaxb.SuperBook object = actualList.get(i); assertEquals("name #" + i, object.getName()); } }