Search in sources :

Example 1 with DateTimeConverter

use of org.apache.camel.component.salesforce.api.utils.DateTimeConverter 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;
}
Also used : AnnotationFieldKeySorter(org.apache.camel.component.salesforce.api.dto.AnnotationFieldKeySorter) TreeMarshallingStrategy(com.thoughtworks.xstream.core.TreeMarshallingStrategy) CompactWriter(com.thoughtworks.xstream.io.xml.CompactWriter) XppDriver(com.thoughtworks.xstream.io.xml.XppDriver) XStream(com.thoughtworks.xstream.XStream) FieldDictionary(com.thoughtworks.xstream.converters.reflection.FieldDictionary) DateTimeConverter(org.apache.camel.component.salesforce.api.utils.DateTimeConverter) NoNameCoder(com.thoughtworks.xstream.io.naming.NoNameCoder) HierarchicalStreamWriter(com.thoughtworks.xstream.io.HierarchicalStreamWriter) ObjectWriter(com.fasterxml.jackson.databind.ObjectWriter) Writer(java.io.Writer) CompactWriter(com.thoughtworks.xstream.io.xml.CompactWriter) PureJavaReflectionProvider(com.thoughtworks.xstream.converters.reflection.PureJavaReflectionProvider)

Example 2 with DateTimeConverter

use of org.apache.camel.component.salesforce.api.utils.DateTimeConverter 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);
}
Also used : CompactWriter(com.thoughtworks.xstream.io.xml.CompactWriter) XppDriver(com.thoughtworks.xstream.io.xml.XppDriver) HierarchicalStreamWriter(com.thoughtworks.xstream.io.HierarchicalStreamWriter) XStream(com.thoughtworks.xstream.XStream) DateTimeConverter(org.apache.camel.component.salesforce.api.utils.DateTimeConverter) NoNameCoder(com.thoughtworks.xstream.io.naming.NoNameCoder) HierarchicalStreamWriter(com.thoughtworks.xstream.io.HierarchicalStreamWriter) Writer(java.io.Writer) CompactWriter(com.thoughtworks.xstream.io.xml.CompactWriter) Test(org.junit.Test)

Aggregations

XStream (com.thoughtworks.xstream.XStream)2 HierarchicalStreamWriter (com.thoughtworks.xstream.io.HierarchicalStreamWriter)2 NoNameCoder (com.thoughtworks.xstream.io.naming.NoNameCoder)2 CompactWriter (com.thoughtworks.xstream.io.xml.CompactWriter)2 XppDriver (com.thoughtworks.xstream.io.xml.XppDriver)2 Writer (java.io.Writer)2 DateTimeConverter (org.apache.camel.component.salesforce.api.utils.DateTimeConverter)2 ObjectWriter (com.fasterxml.jackson.databind.ObjectWriter)1 FieldDictionary (com.thoughtworks.xstream.converters.reflection.FieldDictionary)1 PureJavaReflectionProvider (com.thoughtworks.xstream.converters.reflection.PureJavaReflectionProvider)1 TreeMarshallingStrategy (com.thoughtworks.xstream.core.TreeMarshallingStrategy)1 AnnotationFieldKeySorter (org.apache.camel.component.salesforce.api.dto.AnnotationFieldKeySorter)1 Test (org.junit.Test)1