@Override protected final XMLStreamReader getXMLStreamReader(Class<?> elementType, MediaType mediaType, Unmarshaller u, InputStream entityStream) throws XMLStreamException { JettisonConfig c = JettisonConfig.DEFAULT; final Charset charset = getCharset(mediaType); if (u instanceof JettisonConfigured) { c = ((JettisonConfigured) u).getJSONConfiguration(); } return Stax2JettisonFactory.createReader(new InputStreamReader(entityStream, charset), c); } }
@Override public final void writeCollection(Class<?> elementType, Collection<?> t, MediaType mediaType, Charset c, Marshaller m, OutputStream entityStream) throws JAXBException, IOException { final OutputStreamWriter osw = new OutputStreamWriter(entityStream, c); JettisonConfig origJsonConfig = JettisonConfig.DEFAULT; if (m instanceof JettisonConfigured) { origJsonConfig = ((JettisonConfigured) m).getJSONConfiguration(); } final JettisonConfig unwrappingJsonConfig = JettisonConfig.createJSONConfiguration(origJsonConfig); final XMLStreamWriter jxsw = Stax2JettisonFactory.createWriter(osw, unwrappingJsonConfig); final String invisibleRootName = getRootElementName(elementType); try { jxsw.writeStartDocument(); jxsw.writeStartElement(invisibleRootName); for (Object o : t) { m.marshal(o, jxsw); } jxsw.writeEndElement(); jxsw.writeEndDocument(); jxsw.flush(); } catch (XMLStreamException ex) { Logger.getLogger(JettisonListElementProvider.class.getName()).log(Level.SEVERE, null, ex); throw new JAXBException(ex.getMessage(), ex); } }
@Override protected final XMLStreamReader getXMLStreamReader(Class<?> elementType, MediaType mediaType, Unmarshaller u, InputStream entityStream) throws XMLStreamException { JettisonConfig c = JettisonConfig.DEFAULT; final Charset charset = getCharset(mediaType); if (u instanceof JettisonConfigured) { c = ((JettisonConfigured) u).getJSONConfiguration(); } return Stax2JettisonFactory.createReader(new InputStreamReader(entityStream, charset), c); } }
@Override public final void writeCollection(Class<?> elementType, Collection<?> t, MediaType mediaType, Charset c, Marshaller m, OutputStream entityStream) throws JAXBException, IOException { final OutputStreamWriter osw = new OutputStreamWriter(entityStream, c); JettisonConfig origJsonConfig = JettisonConfig.DEFAULT; if (m instanceof JettisonConfigured) { origJsonConfig = ((JettisonConfigured) m).getJSONConfiguration(); } final JettisonConfig unwrappingJsonConfig = JettisonConfig.createJSONConfiguration(origJsonConfig); final XMLStreamWriter jxsw = Stax2JettisonFactory.createWriter(osw, unwrappingJsonConfig); final String invisibleRootName = getRootElementName(elementType); try { jxsw.writeStartDocument(); jxsw.writeStartElement(invisibleRootName); for (Object o : t) { m.marshal(o, jxsw); } jxsw.writeEndElement(); jxsw.writeEndDocument(); jxsw.flush(); } catch (XMLStreamException ex) { Logger.getLogger(JettisonListElementProvider.class.getName()).log(Level.SEVERE, null, ex); throw new JAXBException(ex.getMessage(), ex); } }