本文整理汇总了Java中org.apache.camel.component.jackson.JacksonDataFormat.setUnmarshalType方法的典型用法代码示例。如果您正苦于以下问题:Java JacksonDataFormat.setUnmarshalType方法的具体用法?Java JacksonDataFormat.setUnmarshalType怎么用?Java JacksonDataFormat.setUnmarshalType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.camel.component.jackson.JacksonDataFormat
的用法示例。
在下文中一共展示了JacksonDataFormat.setUnmarshalType方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: configure
import org.apache.camel.component.jackson.JacksonDataFormat; //导入方法依赖的package包/类
@Override
public void configure() throws Exception {
String s = null;
// Create an instance of JacksonDataFormat to convert to JSON to
// a {@link Notification} instance
JacksonDataFormat format = new JacksonDataFormat();
format.setUnmarshalType(Notification.class);
from(getFromUri())
.routeId(getRouteId())
.startupOrder(getStartUpOrder())
// .log(DEBUG,"headers: ${headers}")
// .log(DEBUG,"body: ${body}")
// .log(DEBUG,"body: ${body}")
// .log(DEBUG,"class: ${body.getClass.toString}")
// .process(new Processor() {
// public void process(Exchange exchange) throws Exception {
// HttpMessage msg = exchange.getIn(HttpMessage.class);
//
// InputStreamCache sis = msg.getBody(InputStreamCache.class);
//
// String s = exchange.getContext().getTypeConverter().convertTo(String.class, sis);
// LOG.debug("process body: " + s);
//
// Message newMessage = new DefaultMessage();
// newMessage.setHeaders(msg.getHeaders());
// newMessage.setBody(s);
// exchange.setIn(newMessage);
// }
// })
// .log(DEBUG,"BEFORE CLASS: ${body.getClass.toString}")
// .log(DEBUG,"BEFORE SIZE: ${body.length}")
// .log(DEBUG,"BEFORE BODY: ${body}")
// .unmarshal().string("UTF-8")
// .log(DEBUG,"AFTER CLASS: ${body.getClass.toString}")
// .log(DEBUG,"AFTER SIZE: ${body.length}")
// .log(DEBUG,"AFTER BODY: ${body}")
.unmarshal().json(JsonLibrary.Jackson,Notification.class)
.to(getToUri());
}
示例2: testRestSwaggerJSON
import org.apache.camel.component.jackson.JacksonDataFormat; //导入方法依赖的package包/类
@Test
public void testRestSwaggerJSON() throws Exception {
JacksonDataFormat jacksonDataFormat = new JacksonDataFormat();
jacksonDataFormat.setUnmarshalType(Customer.class);
CamelContext camelctx = new DefaultCamelContext();
camelctx.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:getCustomerById")
.to("customer:getCustomerById")
.convertBodyTo(String.class)
.unmarshal(jacksonDataFormat);
}
});
RestSwaggerComponent restSwaggerComponent = new RestSwaggerComponent();
restSwaggerComponent.setSpecificationUri(new URI("http://localhost:8080/api/swagger"));
restSwaggerComponent.setComponentName("undertow");
restSwaggerComponent.setConsumes(MediaType.APPLICATION_JSON);
restSwaggerComponent.setProduces(MediaType.APPLICATION_JSON);
camelctx.addComponent("customer", restSwaggerComponent);
camelctx.start();
try {
ProducerTemplate template = camelctx.createProducerTemplate();
Customer customer = template.requestBodyAndHeader("direct:getCustomerById", null, "id", 1, Customer.class);
Assert.assertNotNull(customer);
Assert.assertEquals(1, customer.getId());
} finally {
camelctx.stop();
}
}