当前位置: 首页>>代码示例>>Java>>正文


Java XmlJsonDataFormat类代码示例

本文整理汇总了Java中org.apache.camel.dataformat.xmljson.XmlJsonDataFormat的典型用法代码示例。如果您正苦于以下问题:Java XmlJsonDataFormat类的具体用法?Java XmlJsonDataFormat怎么用?Java XmlJsonDataFormat使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


XmlJsonDataFormat类属于org.apache.camel.dataformat.xmljson包,在下文中一共展示了XmlJsonDataFormat类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: configureXmlJsonDataFormat

import org.apache.camel.dataformat.xmljson.XmlJsonDataFormat; //导入依赖的package包/类
@Bean
@ConditionalOnClass(CamelContext.class)
@ConditionalOnMissingBean(XmlJsonDataFormat.class)
public XmlJsonDataFormat configureXmlJsonDataFormat(
        CamelContext camelContext,
        XmlJsonDataFormatConfiguration configuration) throws Exception {
    XmlJsonDataFormat dataformat = new XmlJsonDataFormat();
    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;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:18,代码来源:XmlJsonDataFormatAutoConfiguration.java

示例2: configure

import org.apache.camel.dataformat.xmljson.XmlJsonDataFormat; //导入依赖的package包/类
@Override
public void configure() throws Exception {
    from("direct:marshal")
        .marshal().xmljson()
        .to("mock:marshalResult");

    from("direct:unmarshal")
        .unmarshal().xmljson()
        .to("mock:unmarshalResult");

    XmlJsonDataFormat xmlJsonFormat = new XmlJsonDataFormat();
    xmlJsonFormat.setRootName("bookstore");
    xmlJsonFormat.setElementName("book");
    xmlJsonFormat.setExpandableProperties(Arrays.asList("author", "author"));

    from("direct:unmarshalBookstore")
        .unmarshal(xmlJsonFormat)
        .to("mock:unmarshalBookstoreResult");
}
 
开发者ID:CamelCookbook,项目名称:camel-cookbook-examples,代码行数:20,代码来源:XmlJsonRoute.java

示例3: configure

import org.apache.camel.dataformat.xmljson.XmlJsonDataFormat; //导入依赖的package包/类
@Override
public void configure() throws Exception {
    final DataFormat bindy = new BindyCsvDataFormat(org.camelcookbook.transformation.csv.model.BookModel.class);
    final DataFormat jaxb = new JaxbDataFormat("org.camelcookbook.transformation.myschema");

    final XmlJsonDataFormat xmlJsonFormat = new XmlJsonDataFormat();
    xmlJsonFormat.setRootName("bookstore");
    xmlJsonFormat.setElementName("book");
    xmlJsonFormat.setExpandableProperties(Arrays.asList("author", "author"));

    from("direct:start")
        .choice()
        .when(header(Exchange.FILE_NAME).endsWith(".csv"))
            .unmarshal(bindy)
            .bean(MyNormalizer.class, "bookModelToJaxb")
            .to("mock:csv")
        .when(header(Exchange.FILE_NAME).endsWith(".json"))
            .unmarshal(xmlJsonFormat)
            .to("mock:json")
        .when(header(Exchange.FILE_NAME).endsWith(".xml"))
            .unmarshal(jaxb)
            .to("mock:xml")
        .otherwise()
            .to("mock:unknown")
            .stop()
        .end()
        .to("mock:normalized");
}
 
开发者ID:CamelCookbook,项目名称:camel-cookbook-examples,代码行数:29,代码来源:NormalizerRoute.java

示例4: testMarshalAndUnmarshal

import org.apache.camel.dataformat.xmljson.XmlJsonDataFormat; //导入依赖的package包/类
@Test
public void testMarshalAndUnmarshal() throws Exception {

    CamelContext camelctx = new DefaultCamelContext();
    camelctx.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            XmlJsonDataFormat format = new XmlJsonDataFormat();
            from("direct:marshal").marshal(format).to("mock:json");
            from("direct:unmarshal").unmarshal(format).to("mock:xml");
        }
    });

    camelctx.start();
    try {
        MockEndpoint mockJSON = camelctx.getEndpoint("mock:json", MockEndpoint.class);
        mockJSON.expectedMessageCount(1);
        mockJSON.expectedHeaderReceived(Exchange.CONTENT_TYPE, "application/json");
        mockJSON.message(0).body().isInstanceOf(byte[].class);

        MockEndpoint mockXML = camelctx.getEndpoint("mock:xml", MockEndpoint.class);
        mockXML.expectedMessageCount(1);
        mockXML.expectedHeaderReceived(Exchange.CONTENT_TYPE, "application/xml");
        mockXML.message(0).body().isInstanceOf(String.class);

        InputStream inStream = getClass().getResourceAsStream("/xmljson/testMessage1.xml");
        String in = camelctx.getTypeConverter().convertTo(String.class, inStream);

        ProducerTemplate template = camelctx.createProducerTemplate();
        Object json = template.requestBody("direct:marshal", in);
        String jsonString = camelctx.getTypeConverter().convertTo(String.class, json);

        String expString = "{'a':'1','b':'2','c':{'a':'c.a.1','b':'c.b.2'},'d':['a','b','c'],'e':['1','2','3'],'f':'true','g':[]}";
        Assert.assertEquals(expString, jsonString.replace('"', '\''));

        template.sendBody("direct:unmarshal", jsonString);

        mockJSON.assertIsSatisfied();
        mockXML.assertIsSatisfied();
    } finally {
        camelctx.stop();
    }
}
 
开发者ID:wildfly-extras,项目名称:wildfly-camel,代码行数:44,代码来源:XmlJsonIntegrationTest.java


注:本文中的org.apache.camel.dataformat.xmljson.XmlJsonDataFormat类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。