use of org.codehaus.jettison.mapped.MappedXMLStreamWriter in project GeoGig by boundlessgeo.
the class JettisonRepresentation method createWriter.
private XMLStreamWriter createWriter(Writer writer) {
final MediaType mediaType = getMediaType();
XMLStreamWriter xml;
if (mediaType.getSubType().equalsIgnoreCase("xml")) {
try {
xml = XMLOutputFactory.newFactory().createXMLStreamWriter(writer);
} catch (XMLStreamException ex) {
throw new RuntimeException(ex);
}
} else if (mediaType == MediaType.APPLICATION_JSON) {
xml = new MappedXMLStreamWriter(new MappedNamespaceConvention(), writer);
} else {
throw new RuntimeException("mediatype not handled " + mediaType);
}
return xml;
}
use of org.codehaus.jettison.mapped.MappedXMLStreamWriter in project opencast by opencast.
the class Event method toJSON.
/**
* Serializes the recording event.
*
* @return the serialized recording event
*/
@Override
public String toJSON() {
try {
if (context == null) {
createJAXBContext();
}
Marshaller marshaller = Event.context.createMarshaller();
Configuration config = new Configuration();
config.setSupressAtAttributes(true);
MappedNamespaceConvention con = new MappedNamespaceConvention(config);
StringWriter writer = new StringWriter();
XMLStreamWriter xmlStreamWriter = new MappedXMLStreamWriter(con, writer) {
@Override
public void writeStartElement(String prefix, String local, String uri) throws XMLStreamException {
super.writeStartElement("", local, "");
}
@Override
public void writeStartElement(String uri, String local) throws XMLStreamException {
super.writeStartElement("", local, "");
}
@Override
public void setPrefix(String pfx, String uri) throws XMLStreamException {
}
@Override
public void setDefaultNamespace(String uri) throws XMLStreamException {
}
};
marshaller.marshal(this, xmlStreamWriter);
return writer.toString();
} catch (JAXBException e) {
throw new IllegalStateException(e.getLinkedException() != null ? e.getLinkedException() : e);
}
}
use of org.codehaus.jettison.mapped.MappedXMLStreamWriter in project cxf by apache.
the class JSONUtils method createStreamWriter.
// CHECKSTYLE:OFF
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;
}
Aggregations