@Override public void setProperty(String name, Object value) throws PropertyException { if (name == null) { throw new IllegalArgumentException("Name can't be null."); } if (name.equals(org.glassfish.jersey.jettison.JettisonMarshaller.FORMATTED)) { if (!(value instanceof Boolean)) { throw new PropertyException("property " + name + " must be an instance of type " + "boolean, not " + value.getClass().getName()); } jsonConfig = JettisonConfig.createJSONConfiguration(jsonConfig); } else { jaxbMarshaller.setProperty(name, value); } }
@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 public void setProperty(String name, Object value) throws PropertyException { if (name == null) { throw new IllegalArgumentException("Name can't be null."); } if (name.equals(org.glassfish.jersey.jettison.JettisonMarshaller.FORMATTED)) { if (!(value instanceof Boolean)) { throw new PropertyException("property " + name + " must be an instance of type " + "boolean, not " + value.getClass().getName()); } jsonConfig = JettisonConfig.createJSONConfiguration(jsonConfig); } else { jaxbMarshaller.setProperty(name, value); } }
@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); } }