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);
}
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);
}
}
Aggregations