use of org.codehaus.jettison.mapped.Configuration in project opencast by opencast.
the class Event method valueOfJson.
/**
* Reads the recording event from the input stream.
*
* @param json
* the input stream
* @return the deserialized recording event
* @throws JSONException
* @throws XMLStreamException
* @throws JAXBException
*/
public static Event 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();
Event event = (Event) unmarshaller.unmarshal(xmlStreamReader);
return event;
}
use of org.codehaus.jettison.mapped.Configuration 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.Configuration in project opencast by opencast.
the class Group method valueOfJson.
/**
* Reads the group from the input stream.
*
* @param json
* the input stream
* @return the deserialized group
* @throws JSONException
* @throws XMLStreamException
* @throws JAXBException
*/
public static Group 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(INDEX_XML_NAMESPACE, "");
config.setXmlToJsonNamespaces(xmlToJsonNamespaces);
MappedNamespaceConvention con = new MappedNamespaceConvention(config);
XMLStreamReader xmlStreamReader = new MappedXMLStreamReader(obj, con);
Unmarshaller unmarshaller = context.createUnmarshaller();
Group event = (Group) unmarshaller.unmarshal(xmlStreamReader);
return event;
}
use of org.codehaus.jettison.mapped.Configuration in project entando-core by entando.
the class JSONProvider method createWriter.
@Override
protected XMLStreamWriter createWriter(Object actualObject, Class<?> actualClass, Type genericType, String enc, OutputStream os, boolean isCollection) throws Exception {
if (BADGER_FISH_CONVENTION.equals(convention)) {
return JSONUtils.createBadgerFishWriter(os);
}
boolean dropElementsInXmlStreamProp = getBooleanJsonProperty(DROP_ELEMENT_IN_XML_PROPERTY, dropElementsInXmlStream);
boolean dropRootNeeded = getBooleanJsonProperty(DROP_ROOT_CONTEXT_PROPERTY, dropRootElement);
boolean dropRootInXmlNeeded = dropRootNeeded && dropElementsInXmlStreamProp;
QName qname = actualClass == Document.class ? org.apache.cxf.helpers.DOMUtils.getElementQName(((Document) actualObject).getDocumentElement()) : this.getQName(actualClass, genericType, actualObject);
if (qname != null && ignoreNamespaces && (isCollection || dropRootInXmlNeeded)) {
qname = new QName(qname.getLocalPart());
}
Configuration config = JSONUtils.createConfiguration(namespaceMap, writeXsiType && !ignoreNamespaces, attributesToElements, typeConverter);
if (namespaceSeparator != null) {
config.setJsonNamespaceSeparator(namespaceSeparator);
}
if (!dropElementsInXmlStreamProp && super.outDropElements != null) {
config.setIgnoredElements(outDropElements);
}
if (!writeNullAsString) {
config.setWriteNullAsString(writeNullAsString);
}
boolean ignoreEmpty = getBooleanJsonProperty(IGNORE_EMPTY_JSON_ARRAY_VALUES_PROPERTY, ignoreEmptyArrayValues);
if (ignoreEmpty) {
config.setIgnoreEmptyArrayValues(ignoreEmpty);
}
if (escapeForwardSlashesAlways) {
config.setEscapeForwardSlashAlways(escapeForwardSlashesAlways);
}
boolean dropRootInJsonStream = dropRootNeeded && !dropElementsInXmlStreamProp;
if (dropRootInJsonStream) {
config.setDropRootElement(true);
}
List<String> theArrayKeys = getArrayKeys();
boolean rootIsArray = isRootArray(theArrayKeys);
if (ignoreNamespaces && rootIsArray && (theArrayKeys == null || dropRootInJsonStream)) {
if (theArrayKeys == null) {
theArrayKeys = new LinkedList<String>();
} else if (dropRootInJsonStream) {
theArrayKeys = new LinkedList<String>(theArrayKeys);
}
if (qname != null) {
theArrayKeys.add(qname.getLocalPart());
}
}
XMLStreamWriter writer = ApsJSONUtils.createStreamWriter(os, qname, writeXsiType && !ignoreNamespaces, config, rootIsArray, theArrayKeys, isCollection || dropRootInXmlNeeded, enc);
writer = ApsJSONUtils.createIgnoreMixedContentWriterIfNeeded(writer, ignoreMixedContent);
writer = ApsJSONUtils.createIgnoreNsWriterIfNeeded(writer, ignoreNamespaces, !writeXsiType);
return createTransformWriterIfNeeded(writer, os, dropElementsInXmlStreamProp);
}
Aggregations