use of org.codehaus.jettison.mapped.Configuration in project jersey by jersey.
the class Stax2JettisonFactory method createWriter.
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;
}
}
use of org.codehaus.jettison.mapped.Configuration in project cxf by apache.
the class JSONUtils method createStreamReader.
public static XMLStreamReader createStreamReader(InputStream is, boolean readXsiType, ConcurrentHashMap<String, String> namespaceMap, String namespaceSeparator, List<String> primitiveArrayKeys, DocumentDepthProperties depthProps, String enc) throws Exception {
if (readXsiType) {
namespaceMap.putIfAbsent(XSI_URI, XSI_PREFIX);
}
Configuration conf = new Configuration(namespaceMap);
if (namespaceSeparator != null) {
conf.setJsonNamespaceSeparator(namespaceSeparator);
}
if (primitiveArrayKeys != null) {
conf.setPrimitiveArrayKeys(new HashSet<>(primitiveArrayKeys));
}
XMLInputFactory factory = depthProps != null ? new JettisonMappedReaderFactory(conf, depthProps) : new MappedXMLInputFactory(conf);
return new JettisonReader(namespaceMap, factory.createXMLStreamReader(is, enc));
}
use of org.codehaus.jettison.mapped.Configuration in project opencast by opencast.
the class Group method toJSON.
@Override
public String toJSON() {
try {
if (context == null) {
createJAXBContext();
}
Marshaller marshaller = Group.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.Configuration in project opencast by opencast.
the class Series method toJSON.
/**
* Serializes the series.
*
* @return the serialized series
*/
@Override
public String toJSON() {
try {
if (context == null) {
createJAXBContext();
}
Marshaller marshaller = Series.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.Configuration in project opencast by opencast.
the class Series method valueOfJson.
/**
* Reads the series from the input stream.
*
* @param json
* the input stream
* @return the deserialized recording event
* @throws JSONException
* @throws XMLStreamException
* @throws JAXBException
*/
public static Series valueOfJson(InputStream json) throws IOException, JSONException, XMLStreamException, JAXBException {
// TODO Get this to work, it is currently returning null properties for all properties.
if (context == null) {
createJAXBContext();
}
BufferedReader streamReader = new BufferedReader(new InputStreamReader(json, "UTF-8"));
StringBuilder jsonStringBuilder = new StringBuilder();
String inputStr;
while ((inputStr = streamReader.readLine()) != null) jsonStringBuilder.append(inputStr);
JSONObject obj = new JSONObject(jsonStringBuilder.toString());
Configuration config = new Configuration();
config.setSupressAtAttributes(true);
Map<String, String> xmlToJsonNamespaces = new HashMap<String, String>(1);
xmlToJsonNamespaces.put(IndexObject.INDEX_XML_NAMESPACE, "");
config.setXmlToJsonNamespaces(xmlToJsonNamespaces);
MappedNamespaceConvention con = new MappedNamespaceConvention(config);
XMLStreamReader xmlStreamReader = new MappedXMLStreamReader(obj, con);
Unmarshaller unmarshaller = context.createUnmarshaller();
Series event = (Series) unmarshaller.unmarshal(xmlStreamReader);
return event;
}
Aggregations