Alternative to deprecated XmlJsonDataFormat in Apache Camel(替代 Apache Camel 中已弃用的 XmlJsonDataFormat)
问题描述
在 Apache Camel 中,我尝试使用 XmlJsonDataFormat 进行从 XML 到 JSON 的快速转换.但是 XMLJSON (http://camel.apache.org/xmljson.html) 已被弃用,所以除了创建处理器之外,我不确定进行这种转换的最佳方法是什么.
In Apache Camel, I was trying to use XmlJsonDataFormat to do a quick conversion from XML to JSON. However the XMLJSON (http://camel.apache.org/xmljson.html) has deprecated so I am not sure what is the best way to do that conversion aside from creating a processor.
有人知道 XmlJsonDataFormat 的替代方法吗?
Does anyone know of an alternative to XmlJsonDataFormat?
推荐答案
经过一些尝试,我通过结合 Jaxb 和 Jackson 将 XML 解组为 POJO,然后将 POJO 解组为 JSON,设法得到了我需要的东西.正如 noMad 指出的那样,我本可以尝试 Dozer (http://camel.apache.org/dozer.html) 也是如此,但没有时间这样做.
After some tries, I have managed to get what I need by combining Jaxb and Jackson for unmarshal XML to POJO and then POJO to JSON. As noMad pointed out, I could have tried Dozer (http://camel.apache.org/dozer.html) as well but haven't got time to do so.
    JacksonDataFormat jacksonDataFormat = new JacksonDataFormat();
    jacksonDataFormat.setPrettyPrint(true);
    jacksonDataFormat.enableFeature(SerializationFeature.WRAP_ROOT_VALUE);
    from("file:src/main/resources/xml/in?noop=true").routeId("lixi-to-json-route").
        unmarshal(new JaxbDataFormat(JAXBContext.newInstance(ApplicationBatch.class))).
        marshal(jacksonDataFormat).
        to("file:src/main/resources/xml/out?fileName=${file:onlyname.noext}.json");
Maven 依赖项
    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-jaxb</artifactId>
    </dependency>
    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-jackson</artifactId>
    </dependency>
                        这篇关于替代 Apache Camel 中已弃用的 XmlJsonDataFormat的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:替代 Apache Camel 中已弃用的 XmlJsonDataFormat
				
        
 
            
        - C++ 和 Java 进程之间的共享内存 2022-01-01
 - 如何使用WebFilter实现授权头检查 2022-01-01
 - value & 是什么意思?0xff 在 Java 中做什么? 2022-01-01
 - 将log4j 1.2配置转换为log4j 2配置 2022-01-01
 - Spring Boot连接到使用仲裁器运行的MongoDB副本集 2022-01-01
 - 从 finally 块返回时 Java 的奇怪行为 2022-01-01
 - Safepoint+stats 日志,输出 JDK12 中没有 vmop 操作 2022-01-01
 - Eclipse 插件更新错误日志在哪里? 2022-01-01
 - Jersey REST 客户端:发布多部分数据 2022-01-01
 - Java包名称中单词分隔符的约定是什么? 2022-01-01
 
						
						
						
						
						