1 Answer

  1. Matthew- Reply

    2019-11-13

    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 dependencies

        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-jaxb</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-jackson</artifactId>
        </dependency>
    

Leave a Reply

Your email address will not be published. Required fields are marked *

You can use these HTML tags and attributes <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>