use of com.thoughtworks.xstream.io.xml.CompactWriter in project camel by apache.
the class DefaultCompositeApiClient method configureXStream.
static XStream configureXStream() {
final PureJavaReflectionProvider reflectionProvider = new PureJavaReflectionProvider(new FieldDictionary(new AnnotationFieldKeySorter()));
final XppDriver hierarchicalStreamDriver = new XppDriver(new NoNameCoder()) {
@Override
public HierarchicalStreamWriter createWriter(final Writer out) {
return new CompactWriter(out, getNameCoder());
}
};
final XStream xStream = new XStream(reflectionProvider, hierarchicalStreamDriver);
xStream.aliasSystemAttribute(null, "class");
xStream.ignoreUnknownElements();
XStreamUtils.addDefaultPermissions(xStream);
xStream.registerConverter(new DateTimeConverter());
xStream.setMarshallingStrategy(new TreeMarshallingStrategy());
xStream.processAnnotations(ADDITIONAL_TYPES);
return xStream;
}
use of com.thoughtworks.xstream.io.xml.CompactWriter in project camel by apache.
the class ApprovalRequestsTest method shouldSerializeAsXml.
@Test
public void shouldSerializeAsXml() {
final String xml = //
"<ProcessApprovalRequest>" + //
"<requests>" + //
"<actionType>Submit</actionType>" + //
"<contextActorId>005D00000015rZy</contextActorId>" + //
"<contextId>001D000000I8mIm</contextId>" + //
"<comments>this is a test 1</comments>" + //
"<nextApproverIds>005D00000015rY9</nextApproverIds>" + //
"<processDefinitionNameOrId>PTO_Request_Process</processDefinitionNameOrId>" + //
"<skipEntryCriteria>true</skipEntryCriteria>" + //
"</requests>" + //
"<requests>" + //
"<actionType>Submit</actionType>" + //
"<contextActorId>005D00000015rZy</contextActorId>" + //
"<contextId>001D000000I8dIm</contextId>" + //
"<comments>this is a test 2</comments>" + //
"<nextApproverIds>005D00000015xY9</nextApproverIds>" + //
"<processDefinitionNameOrId>PTO_Request_Process</processDefinitionNameOrId>" + //
"<skipEntryCriteria>true</skipEntryCriteria>" + //
"</requests>" + "</ProcessApprovalRequest>";
final XStream xStream = new XStream(new XppDriver(new NoNameCoder()) {
@Override
public HierarchicalStreamWriter createWriter(final Writer out) {
return new CompactWriter(out, getNameCoder());
}
});
xStream.ignoreUnknownElements();
XStreamUtils.addDefaultPermissions(xStream);
xStream.registerConverter(new DateTimeConverter());
xStream.processAnnotations(ApprovalRequests.class);
final String serialized = xStream.toXML(requests);
assertEquals("Approval requests should serialize as XML", xml, serialized);
}
use of com.thoughtworks.xstream.io.xml.CompactWriter in project openolat by klemens.
the class ViteroManager method serializeViteroBooking.
private final String serializeViteroBooking(ViteroBooking booking) {
StringWriter writer = new StringWriter();
xStream.marshal(booking, new CompactWriter(writer));
writer.flush();
return writer.toString();
}
use of com.thoughtworks.xstream.io.xml.CompactWriter in project openolat by klemens.
the class OpenMeetingsDAO method serializeRoom.
public String serializeRoom(OpenMeetingsRoom room) {
StringWriter writer = new StringWriter();
xStream.marshal(room, new CompactWriter(writer));
writer.flush();
return writer.toString();
}
use of com.thoughtworks.xstream.io.xml.CompactWriter in project ddf by codice.
the class XStreamAttributeCopier method copyXml.
/**
* Copies the entire XML element {@code reader} is currently at into {@code writer} and returns a
* new reader ready to read the copied element. After the call, {@code reader} will be at the end
* of the element that was copied.
*
* <p>If {@code attributeMap} is provided, the attributes will be added to the copy.
*
* @param reader the reader currently at the XML element you want to copy
* @param writer the writer that the element will be copied into
* @param attributeMap the map of attribute names to values that will be added as attributes of
* the copy, may be null
* @return a new reader ready to read the copied element
* @throws ConversionException if a parser to use for the new reader can't be created
*/
public static HierarchicalStreamReader copyXml(HierarchicalStreamReader reader, StringWriter writer, Map<String, String> attributeMap) {
copyElementWithAttributes(reader, new CompactWriter(writer, new NoNameCoder()), attributeMap);
XmlPullParser parser;
try {
parser = XmlPullParserFactory.newInstance().newPullParser();
} catch (XmlPullParserException e) {
throw new ConversionException("Unable to create XmlPullParser, cannot parse XML.", e);
}
return new XppReader(new InputStreamReader(IOUtils.toInputStream(writer.toString(), StandardCharsets.UTF_8)), parser);
}
Aggregations