public XMLStreamWriter createXMLStreamWriter(Writer writer) throws XMLStreamException { return new MappedXMLStreamWriter(convention, writer); } }
public void writeAttribute(String local, String value) throws XMLStreamException { writeAttribute(null, local, value); }
public static XMLStreamWriter createWriter(final Writer writer, final JettisonConfig config) throws IOException { switch (config.getNotation()) { case BADGERFISH: return new BadgerFishXMLStreamWriter(writer); case MAPPED_JETTISON: Configuration jmConfig; if (null == config.getXml2JsonNs()) { jmConfig = new Configuration(); } else { jmConfig = new Configuration(config.getXml2JsonNs()); } final MappedXMLStreamWriter result = new MappedXMLStreamWriter(new MappedNamespaceConvention(jmConfig), writer); for (String array : config.getArrayElements()) { result.serializeAsArray(array); } return result; default: return null; } }
public void writeAttribute(String p, String ns, String local, String value) throws XMLStreamException { if (convention.isElement(p, ns, local)) { writeStartElement(p, local, ns); writeCharacters(value); writeEndElement(); return; } String key = convention.createAttributeKey(p, ns, local); try { if (current instanceof JSONArray) { JSONArray array = ((JSONArray) current); current = array.get(array.length() - 1); } makeCurrentJSONObject(); if (current instanceof JSONObject) { Object o = ((JSONObject) current).opt(key); if (o == null) { ((JSONObject) current).put(key, value); } } } catch (JSONException e) { throw new XMLStreamException(e); } }
@Override public void writeStartElement(String prefix, String local, String uri) throws XMLStreamException { super.writeStartElement("", local, ""); }
@Override public void writeCharacters(String text) throws XMLStreamException { if (CDataAdapter.isCdata(new String(text))) { String parsedCDataText = CDataAdapter.parse(new String(text)); super.writeCharacters(parsedCDataText); } else { super.writeCharacters(text); } }
public static XMLStreamWriter createWriter(final Writer writer, final JettisonConfig config) throws IOException { switch (config.getNotation()) { case BADGERFISH: return new BadgerFishXMLStreamWriter(writer); case MAPPED_JETTISON: Configuration jmConfig; if (null == config.getXml2JsonNs()) { jmConfig = new Configuration(); } else { jmConfig = new Configuration(config.getXml2JsonNs()); } final MappedXMLStreamWriter result = new MappedXMLStreamWriter(new MappedNamespaceConvention(jmConfig), writer); for (String array : config.getArrayElements()) { result.serializeAsArray(array); } return result; default: return null; } }
@Override public void writeStartElement(String uri, String local) throws XMLStreamException { super.writeStartElement("", local, ""); }
@Override public void writeCharacters(String text) throws XMLStreamException { if (CDataAdapter.isCdata(text)) { String parsedCDataText = CDataAdapter.parse(text); super.writeCharacters(parsedCDataText); } else { super.writeCharacters(text); } }
public XMLStreamWriter createXMLStreamWriter(Writer writer) throws XMLStreamException { return new MappedXMLStreamWriter(convention, writer); } }
@Override public void writeStartElement(String prefix, String local, String uri) throws XMLStreamException { super.writeStartElement("", local, ""); }
public void writeAttribute(String ns, String local, String value) throws XMLStreamException { writeAttribute(null, ns, local, value); }
public void marshal(Object o, Writer writer) throws JAXBException { MappedXMLStreamWriter mapped = new MappedXMLStreamWriter(convention, writer); marshaller.marshal(o, mapped); }
@Override public void writeStartElement(String uri, String local) throws XMLStreamException { super.writeStartElement("", local, ""); }
public void writeAttribute(String local, String value) throws XMLStreamException { writeAttribute(null, local, value); }
private String marshall(Object object) throws JAXBException { try { StringWriter writer = new StringWriter(); MappedXMLStreamWriter mappedXMLStreamWriter = new MappedXMLStreamWriter(convention, writer); // AbstractXMLStreamWriter mappedXMLStreamWriter = new BadgerFishXMLStreamWriter(writer); marshaller.marshal(object, mappedXMLStreamWriter); return writer.toString(); } catch (JAXBException e) { log.error("Error marshalling Object: " + object, e); throw e; } } }
public void writeAttribute(String ns, String local, String value) throws XMLStreamException { writeAttribute(null, ns, local, value); }
jmConfig = new Configuration(config.getXml2JsonNs()); return new MappedXMLStreamWriter(new MappedNamespaceConvention(jmConfig), writer); default: return null;
public static XMLStreamWriter createStreamWriter(OutputStream os, QName qname, boolean writeXsiType, Configuration config, boolean serializeAsArray, List<String> arrayKeys, boolean dropRootElement, String enc) throws Exception { //CHECKSTYLE:ON MappedNamespaceConvention convention = new MappedNamespaceConvention(config); AbstractXMLStreamWriter xsw = new MappedXMLStreamWriter( convention, new OutputStreamWriter(os, enc)); if (serializeAsArray) { if (arrayKeys != null) { for (String key : arrayKeys) { xsw.serializeAsArray(key); } } else if (qname != null) { String key = getKey(convention, qname); xsw.serializeAsArray(key); } } return !writeXsiType || dropRootElement ? new IgnoreContentJettisonWriter(xsw, writeXsiType, dropRootElement) : xsw; }
private static String convertToJSON(Element rootElement) throws Exception { Configuration config = new Configuration(); config.setTypeConverter(new SimpleConverter()); MappedNamespaceConvention con = new MappedNamespaceConvention(config); StringWriter strWriter = new StringWriter(); AbstractXMLStreamWriter w = new MappedXMLStreamWriter(con, strWriter); w.writeStartDocument(); converToJSON(rootElement, w); w.writeEndDocument(); w.close(); strWriter.close(); String jsonString = strWriter.toString(); StringWriter wr = new StringWriter(); StringEscapeUtils.unescapeJavaScript(wr, jsonString); String result = wr.toString(); return result; }