use of org.apache.camel.component.snakeyaml.SnakeYAMLDataFormat in project camel by apache.
the class SnakeYAMLDataFormatAutoConfiguration method configureSnakeYAMLDataFormatFactory.
@Bean(name = "yaml-snakeyaml-dataformat-factory")
@ConditionalOnClass(CamelContext.class)
@ConditionalOnMissingBean(SnakeYAMLDataFormat.class)
public DataFormatFactory configureSnakeYAMLDataFormatFactory(final CamelContext camelContext, final SnakeYAMLDataFormatConfiguration configuration) {
return new DataFormatFactory() {
public DataFormat newInstance() {
SnakeYAMLDataFormat dataformat = new SnakeYAMLDataFormat();
if (CamelContextAware.class.isAssignableFrom(SnakeYAMLDataFormat.class)) {
CamelContextAware contextAware = CamelContextAware.class.cast(dataformat);
if (contextAware != null) {
contextAware.setCamelContext(camelContext);
}
}
try {
Map<String, Object> parameters = new HashMap<>();
IntrospectionSupport.getProperties(configuration, parameters, null, false);
IntrospectionSupport.setProperties(camelContext, camelContext.getTypeConverter(), dataformat, parameters);
} catch (Exception e) {
throw new RuntimeCamelException(e);
}
return dataformat;
}
};
}
use of org.apache.camel.component.snakeyaml.SnakeYAMLDataFormat in project wildfly-camel by wildfly-extras.
the class YamlDataFormatIntegrationTest method testUnmarshalYaml.
@Test
public void testUnmarshalYaml() throws Exception {
SnakeYAMLDataFormat yaml = new SnakeYAMLDataFormat();
yaml.addTypeFilters(TypeFilters.types(Customer.class));
CamelContext camelctx = new DefaultCamelContext();
camelctx.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:start").unmarshal(yaml);
}
});
camelctx.start();
try {
ProducerTemplate template = camelctx.createProducerTemplate();
Customer result = template.requestBody("direct:start", CUSTOMER_YAML, Customer.class);
Assert.assertNotNull(result);
Assert.assertEquals("John", result.getFirstName());
Assert.assertEquals("Doe", result.getLastName());
} finally {
camelctx.stop();
}
}
Aggregations