Search in sources :

Example 1 with JettisonConfig

use of org.glassfish.jersey.jettison.JettisonConfig in project jersey by jersey.

the class JettisonListElementProvider method getXMLStreamReader.

@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);
}
Also used : InputStreamReader(java.io.InputStreamReader) JettisonConfigured(org.glassfish.jersey.jettison.JettisonConfigured) JettisonConfig(org.glassfish.jersey.jettison.JettisonConfig) Charset(java.nio.charset.Charset)

Example 2 with JettisonConfig

use of org.glassfish.jersey.jettison.JettisonConfig in project jersey by jersey.

the class JettisonListElementProvider method writeCollection.

@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);
    }
}
Also used : XMLStreamException(javax.xml.stream.XMLStreamException) JettisonConfigured(org.glassfish.jersey.jettison.JettisonConfigured) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) JAXBException(javax.xml.bind.JAXBException) JettisonConfig(org.glassfish.jersey.jettison.JettisonConfig) OutputStreamWriter(java.io.OutputStreamWriter)

Aggregations

JettisonConfig (org.glassfish.jersey.jettison.JettisonConfig)2 JettisonConfigured (org.glassfish.jersey.jettison.JettisonConfigured)2 InputStreamReader (java.io.InputStreamReader)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Charset (java.nio.charset.Charset)1 JAXBException (javax.xml.bind.JAXBException)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)1