/** * Construct a JettisonMappedXmlDriver with configuration. This constructor has been added * by special request of Jettison users to support JSON generated by older Jettison * versions. if the driver is setup to ignore the XStream hints for JSON arrays, there is * neither support from XStream's side nor are there any tests to ensure this mode. * * @param config the Jettison configuration * @param useSerializeAsArray flag to use XStream's hints for collections and arrays * @since 1.4 */ public JettisonMappedXmlDriver(final Configuration config, final boolean useSerializeAsArray) { mof = new MappedXMLOutputFactory(config); mif = new MappedXMLInputFactory(config); convention = new MappedNamespaceConvention(config); this.useSerializeAsArray = useSerializeAsArray; }
public MappedDOMDocumentSerializer(OutputStream output, Configuration con) { super(output, new MappedXMLOutputFactory(con)); }
public JettisonMappedXmlDriver() { final HashMap nstjsons = new HashMap(); mof = new MappedXMLOutputFactory(nstjsons); mif = new MappedXMLInputFactory(nstjsons); }
public JsonDataFormat() { final Map<?, ?> nstjsons = new HashMap<>(); mof = new MappedXMLOutputFactory(nstjsons); mif = new MappedXMLInputFactory(nstjsons); }
public XStreamConverter() { this.classMapper = new DefaultClassMapper(); Map nstjsons = new HashMap(); this.outputFactory = new MappedXMLOutputFactory(nstjsons); this.inputFactory = new MappedXMLInputFactory(nstjsons); this.objectMapper = new XStream(); }
public XStreamConverter() { this.classMapper = new DefaultClassMapper(); Map nstjsons = new HashMap(); this.outputFactory = new MappedXMLOutputFactory(nstjsons); this.inputFactory = new MappedXMLInputFactory(nstjsons); this.objectMapper = new XStream(); }
public JettisonMappedXmlDriver(final Configuration config, final boolean useSerializeAsArray) { mof = new MappedXMLOutputFactory(config); mif = new MappedXMLInputFactory(config); convention = new MappedNamespaceConvention(config); this.useSerializeAsArray = useSerializeAsArray; }
import org.codehaus.jettison.mapped.MappedXMLOutputFactory; import javax.xml.stream.XMLEventReader; import javax.xml.stream.XMLEventWriter; import javax.xml.stream.XMLInputFactory; import java.io.StringReader; import java.util.HashMap; public class Main { public static void main(String[] args) throws Exception { String xml = "<root><foo>foo string</foo><bar><x>1</x><y>5</y></bar></root>"; XMLEventReader reader = XMLInputFactory.newInstance() .createXMLEventReader(new StringReader(xml)); XMLEventWriter writer = new MappedXMLOutputFactory(new HashMap()) .createXMLEventWriter(System.out); writer.add(reader); writer.close(); reader.close(); } }
public JettisonMappedXmlDriver() { final HashMap nstjsons = new HashMap(); final Configuration config = new Configuration(nstjsons); mof = new MappedXMLOutputFactory(config); mif = new MappedXMLInputFactory(config); convention = new MappedNamespaceConvention(config); }
/** * Construct a JettisonMappedXmlDriver with configuration. This constructor has been added * by special request of Jettison users to support JSON generated by older Jettison * versions. if the driver is setup to ignore the XStream hints for JSON arrays, there is * neither support from XStream's side nor are there any tests to ensure this mode. * * @param config the Jettison configuration * @param useSerializeAsArray flag to use XStream's hints for collections and arrays * @since 1.4 */ public JettisonMappedXmlDriver(final Configuration config, final boolean useSerializeAsArray) { mof = new MappedXMLOutputFactory(config); mif = new MappedXMLInputFactory(config); convention = new MappedNamespaceConvention(config); this.useSerializeAsArray = useSerializeAsArray; }
/** * Construct a JettisonMappedXmlDriver with configuration. This constructor has been added * by special request of Jettison users to support JSON generated by older Jettison * versions. if the driver is setup to ignore the XStream hints for JSON arrays, there is * neither support from XStream's side nor are there any tests to ensure this mode. * * @param config the Jettison configuration * @param useSerializeAsArray flag to use XStream's hints for collections and arrays * @since 1.4 */ public JettisonMappedXmlDriver(final Configuration config, final boolean useSerializeAsArray) { mof = new MappedXMLOutputFactory(config); mif = new MappedXMLInputFactory(config); convention = new MappedNamespaceConvention(config); this.useSerializeAsArray = useSerializeAsArray; }
/** * Construct a JettisonMappedXmlDriver with configuration. This constructor has been added * by special request of Jettison users to support JSON generated by older Jettison * versions. if the driver is setup to ignore the XStream hints for JSON arrays, there is * neither support from XStream's side nor are there any tests to ensure this mode. * * @param config the Jettison configuration * @param useSerializeAsArray flag to use XStream's hints for collections and arrays * @since 1.4 */ public JettisonMappedXmlDriver(final Configuration config, final boolean useSerializeAsArray) { mof = new MappedXMLOutputFactory(config); mif = new MappedXMLInputFactory(config); convention = new MappedNamespaceConvention(config); this.useSerializeAsArray = useSerializeAsArray; }
public JettisonMappedXmlDriver() { final HashMap nstjsons = new HashMap(); final Configuration config = new Configuration(nstjsons); mof = new MappedXMLOutputFactory(config); mif = new MappedXMLInputFactory(config); convention = new MappedNamespaceConvention(config); }
/** * Construct a JettisonMappedXmlDriver with configuration. This constructor has been added * by special request of Jettison users to support JSON generated by older Jettison * versions. if the driver is setup to ignore the XStream hints for JSON arrays, there is * neither support from XStream's side nor are there any tests to ensure this mode. * * @param config the Jettison configuration * @param useSerializeAsArray flag to use XStream's hints for collections and arrays * @since 1.4 */ public JettisonMappedXmlDriver(final Configuration config, final boolean useSerializeAsArray) { mof = new MappedXMLOutputFactory(config); mif = new MappedXMLInputFactory(config); convention = new MappedNamespaceConvention(config); this.useSerializeAsArray = useSerializeAsArray; }
/** * Construct a JettisonMappedXmlDriver with configuration. This constructor has been added * by special request of Jettison users to support JSON generated by older Jettison * versions. if the driver is setup to ignore the XStream hints for JSON arrays, there is * neither support from XStream's side nor are there any tests to ensure this mode. * * @param config the Jettison configuration * @param useSerializeAsArray flag to use XStream's hints for collections and arrays * @since 1.4 */ public JettisonMappedXmlDriver(final Configuration config, final boolean useSerializeAsArray) { mof = new MappedXMLOutputFactory(config); mif = new MappedXMLInputFactory(config); convention = new MappedNamespaceConvention(config); this.useSerializeAsArray = useSerializeAsArray; }
/** {@inheritDoc} */ @Override public void writeTo(XmlObject obj, Class<?> cls, Type genericType, Annotation[] annotations, MediaType m, MultivaluedMap<String, Object> headers, OutputStream os) { try { // Set up the JSON StAX implementation Map<String, String> nstojns = new HashMap<String, String>(); XMLOutputFactory factory = new MappedXMLOutputFactory(nstojns); XMLStreamWriter xsw = factory.createXMLStreamWriter(os); xsw.writeStartDocument(); if (obj != null) { XmlObject xObj = obj; XMLBeanStreamSerializer ser = new XMLBeanStreamSerializer(); ser.serialize(xObj, xsw); } xsw.flush(); xsw.close(); } catch (XMLStreamException e) { throw ExceptionUtils.toInternalServerErrorException(e, null); } catch (IOException ioe) { throw ExceptionUtils.toInternalServerErrorException(ioe, null); } } }
@SuppressWarnings(value={"unchecked"}) private String convertXmlToJson(String xmlToConvert) throws ParseException { if (xmlToConvert == null) { throw new ParseException("Unable to convert XML to JSON", 0); } try { String xmlWithoutBreaks = removeLineBreaks(xmlToConvert); byte[] xmlByteArray = xmlWithoutBreaks.getBytes(); Configuration config = new Configuration(); if (null != namespaces && !namespaces.isEmpty()) { config.getXmlToJsonNamespaces().putAll(namespaces); } ByteArrayInputStream source = new ByteArrayInputStream(xmlByteArray); AbstractXMLOutputFactory writerFactory = new MappedXMLOutputFactory(config); ByteArrayOutputStream output = serialise(source, writerFactory); return new String(output.toByteArray()); } catch (IOException e) { ParseException ex = new ParseException("Unable to convert XML to JSON", 0); ex.setStackTrace(e.getStackTrace()); throw ex; } }
@Override protected XMLStreamWriter getJSONWriter(Writer writer, MessageContext messageContext) throws XMLStreamException { return new MappedXMLOutputFactory(JSONUtil.getNS2JNSMap( messageContext.getAxisService())).createXMLStreamWriter(writer); } }
@Override protected XMLStreamWriter getJSONWriter(Writer writer, MessageContext messageContext) throws XMLStreamException { return new MappedXMLOutputFactory(JSONUtil.getNS2JNSMap( messageContext.getAxisService())).createXMLStreamWriter(writer); } }
/** * Construct a JettisonMappedXmlDriver with configuration. * <p> * This constructor has been added by special request of Jettison users to support JSON generated by older Jettison * versions. if the driver is setup to ignore the XStream hints for JSON arrays, there is neither support from * XStream's side nor are there any tests to ensure this mode. * </p> * * @param config the Jettison configuration * @param useSerializeAsArray flag to use XStream's hints for collections and arrays * @since 1.4 */ public JettisonMappedXmlDriver(Configuration config, final boolean useSerializeAsArray) { config = config == null ? new Configuration() : config; mof = new MappedXMLOutputFactory(config); mif = new MappedXMLInputFactory(config); convention = new MappedNamespaceConvention(config); this.useSerializeAsArray = useSerializeAsArray; }