本文整理汇总了Java中org.apache.camel.component.jackson.JacksonDataFormat类的典型用法代码示例。如果您正苦于以下问题:Java JacksonDataFormat类的具体用法?Java JacksonDataFormat怎么用?Java JacksonDataFormat使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JacksonDataFormat类属于org.apache.camel.component.jackson包,在下文中一共展示了JacksonDataFormat类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: configureJacksonDataFormat
import org.apache.camel.component.jackson.JacksonDataFormat; //导入依赖的package包/类
@Bean
@ConditionalOnClass(CamelContext.class)
@ConditionalOnMissingBean(JacksonDataFormat.class)
public JacksonDataFormat configureJacksonDataFormat(
CamelContext camelContext,
JacksonDataFormatConfiguration configuration) throws Exception {
JacksonDataFormat dataformat = new JacksonDataFormat();
if (dataformat instanceof CamelContextAware) {
((CamelContextAware) dataformat).setCamelContext(camelContext);
}
Map<String, Object> parameters = new HashMap<>();
IntrospectionSupport.getProperties(configuration, parameters, null,
false);
IntrospectionSupport.setProperties(camelContext,
camelContext.getTypeConverter(), dataformat, parameters);
return dataformat;
}
示例2: init
import org.apache.camel.component.jackson.JacksonDataFormat; //导入依赖的package包/类
@Before
public void init()
{
ObjectMapper mapper = ObjectMapperFactory.createInstance();
dataFormat = new JacksonDataFormat(mapper, Object.class);
String expectedClassMapKey1 =
isClassMapKeySerializedWithPrefix() ? "class java.lang.Long" : "java.lang.Long";
expectedJson = "{" +
"\"@class\":\"" + SimplePojo.class.getCanonicalName() + "\"," +
"\"field1\":\"" + EXPECTED_FIELD1_VALUE + "\"," +
"\"field2\":" + EXPECTED_FIELD2_VALUE + "," +
"\"field3\":\"" + EXPECTED_FIELD3_VALUE + "\"," +
"\"field4\":{\"@class\":\"java.util.HashMap\"," +
"\"" + expectedClassMapKey1 + "\":\"" + EXPECTED_CLASS_MAP_VALUE1 + "\"}," +
"\"field5\":{\"@class\":\"java.util.HashMap\"," +
"\"" + EXPECTED_STRING_MAP_KEY1 + "\":\"" + EXPECTED_STRING_MAP_VALUE1 + "\"}" +
"}";
}
示例3: 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());
}
示例4: createRouteBuilder
import org.apache.camel.component.jackson.JacksonDataFormat; //导入依赖的package包/类
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
public void configure() {
JacksonDataFormat jdf = new JacksonDataFormat(TemperaturePojo.class);
from("direct:start")
.unmarshal(jdf)
.to("mock:result");
}
};
}
示例5: initializeCamelEndpoint
import org.apache.camel.component.jackson.JacksonDataFormat; //导入依赖的package包/类
/**
* Initializes a Camel context and configures routes and object marshaling with the given
* brokerUrl, enpoint, and messageConsumer.
*
* @param brokerUrl
* @param endpoint
* @param messageConsumer
* @return the Gytheio message producer
* @throws Exception
*/
protected MessageProducer initializeCamelEndpoint(
final String brokerUrl, final String endpointSend, final String endpointReceive,
final MessageConsumer messageConsumer) throws Exception
{
CamelContext context = new DefaultCamelContext();
ConnectionFactory connectionFactory =
new ActiveMQConnectionFactory(brokerUrl);
JmsComponent component = AMQPComponent.jmsComponent();
component.setConnectionFactory(connectionFactory);
context.addComponent("amqp", component);
final DataFormat dataFormat = new JacksonDataFormat(
ObjectMapperFactory.createInstance(), Object.class);
if (messageConsumer != null)
{
context.addRoutes(new RouteBuilder() {
public void configure() {
from("amqp:" + endpointReceive).unmarshal(dataFormat).bean(messageConsumer, "onReceive");
}
});
}
context.addRoutes(new RouteBuilder() {
public void configure() {
from("direct:benchmark.test").marshal(dataFormat).to("amqp:" + endpointSend);
}
});
CamelMessageProducer messageProducer = new CamelMessageProducer();
messageProducer.setProducer(context.createProducerTemplate());
messageProducer.setEndpoint("direct:benchmark.test");
context.start();
return messageProducer;
}
示例6: testJsonIgnore
import org.apache.camel.component.jackson.JacksonDataFormat; //导入依赖的package包/类
@Test
public void testJsonIgnore() throws Exception {
CamelContext camelctx = new DefaultCamelContext();
camelctx.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
JacksonDataFormat jacksonDataFormat = new JacksonDataFormat();
jacksonDataFormat.setPrettyPrint(false);
from("direct:start")
.process(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
Organization organization = new Organization();
organization.setName("The Organization");
Employee employee = new Employee();
employee.setName("The Manager");
employee.setEmployeeNumber(12345);
employee.setOrganization(organization);
organization.setManager(employee);
exchange.getIn().setBody(employee);
}
})
.marshal(jacksonDataFormat);
}
});
camelctx.start();
try {
ProducerTemplate template = camelctx.createProducerTemplate();
String result = template.requestBody("direct:start", null, String.class);
Assert.assertEquals("{\"name\":\"The Manager\"}", result);
} finally {
camelctx.stop();
}
}
示例7: 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();
}
}
示例8: configure
import org.apache.camel.component.jackson.JacksonDataFormat; //导入依赖的package包/类
@Override
public void configure() throws Exception {
DataFormat jsonDataFormat = new JacksonDataFormat();
from("cxfrs:bean:rsReportsServer?bindingStyle=SimpleConsumer")
.log("Executing ${header.operationName}")
.doTry()
.beanRef("authBean", "isLoggedIn")
.beanRef("authBean", "canAccessReport")
.recipientList(simple("direct:rs-${header.operationName}")).end()
.doCatch(AuthenticationException.class)
.log("Authentication failed ${header.operationName}")
.beanRef("authBean", "buildAuthFail")
.marshal(jsonDataFormat)
.doCatch(AuthorizationException.class)
.log("Report authorization failed ${header.operationName} ${header.reportId}")
.beanRef("reportBean", "noSuchReport")
.marshal(jsonDataFormat)
.end()
.routeId("cxfrsReportsInRouteId");
from("direct:rs-reportDetails")
.beanRef("reportBean", "getReportsDetailed")
.marshal().json(JsonLibrary.Jackson)
.routeId("rsReportDetailsRouteId");
from("direct:rs-runReport")
.beanRef("reportBean", "run")
.marshal().json(JsonLibrary.Jackson)
.routeId("rsRunReportRouteId");
from("direct:rs-detailsAndRunReport")
.beanRef("reportBean", "detailsAndRun")
.marshal().json(JsonLibrary.Jackson)
.routeId("rsDetailsAndRunReportRouteId");
from("direct:rs-exportReport")
.beanRef("reportBean", "export")
.routeId("rsExportReportRouteId");
}
示例9: createRegistry
import org.apache.camel.component.jackson.JacksonDataFormat; //导入依赖的package包/类
@Override
protected JndiRegistry createRegistry() throws Exception {
JndiRegistry jndi = super.createRegistry();
jndi.bind("bla", new JacksonDataFormat());
return jndi;
}