Search in sources :

Example 1 with BoonDataFormat

use of org.apache.camel.model.dataformat.BoonDataFormat in project camel by apache.

the class DataFormatClause method boon.

/**
     * Uses the Boon data format
     *
     * @param classType the POJO class type
     */
public T boon(Class<?> classType) {
    BoonDataFormat boon = new BoonDataFormat();
    boon.setUnmarshalType(classType);
    return dataFormat(boon);
}
Also used : BoonDataFormat(org.apache.camel.model.dataformat.BoonDataFormat)

Example 2 with BoonDataFormat

use of org.apache.camel.model.dataformat.BoonDataFormat in project wildfly-camel by wildfly-extras.

the class BoonDataFormatTest method testMarshal.

@Test
public void testMarshal() throws Exception {
    CamelContext camelctx = new DefaultCamelContext();
    camelctx.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("direct:start").marshal(new BoonDataFormat(Customer.class));
        }
    });
    String expected = "{'firstName':'John','lastName':'Doe'}";
    camelctx.start();
    try {
        ProducerTemplate producer = camelctx.createProducerTemplate();
        String result = producer.requestBody("direct:start", new Customer("John", "Doe"), String.class);
        Assert.assertEquals(expected.replace('\'', '"'), result);
    } finally {
        camelctx.stop();
    }
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) ProducerTemplate(org.apache.camel.ProducerTemplate) RouteBuilder(org.apache.camel.builder.RouteBuilder) Customer(org.wildfly.camel.test.common.types.Customer) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) BoonDataFormat(org.apache.camel.model.dataformat.BoonDataFormat) Test(org.junit.Test)

Example 3 with BoonDataFormat

use of org.apache.camel.model.dataformat.BoonDataFormat in project wildfly-camel by wildfly-extras.

the class BoonDataFormatTest method testUnmarshal.

@Test
public void testUnmarshal() throws Exception {
    CamelContext camelctx = new DefaultCamelContext();
    camelctx.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("direct:start").unmarshal(new BoonDataFormat(Customer.class));
        }
    });
    String input = "{'firstName':'John','lastName':'Doe'}";
    camelctx.start();
    try {
        ProducerTemplate producer = camelctx.createProducerTemplate();
        Customer customer = producer.requestBody("direct:start", input, Customer.class);
        Assert.assertEquals("John", customer.getFirstName());
        Assert.assertEquals("Doe", customer.getLastName());
    } finally {
        camelctx.stop();
    }
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) ProducerTemplate(org.apache.camel.ProducerTemplate) RouteBuilder(org.apache.camel.builder.RouteBuilder) Customer(org.wildfly.camel.test.common.types.Customer) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) BoonDataFormat(org.apache.camel.model.dataformat.BoonDataFormat) Test(org.junit.Test)

Aggregations

BoonDataFormat (org.apache.camel.model.dataformat.BoonDataFormat)3 CamelContext (org.apache.camel.CamelContext)2 ProducerTemplate (org.apache.camel.ProducerTemplate)2 RouteBuilder (org.apache.camel.builder.RouteBuilder)2 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)2 Test (org.junit.Test)2 Customer (org.wildfly.camel.test.common.types.Customer)2