0

In all examples I see over the internet, need to call "setContext". but this function doesn't exist in JaxbDataFormat . Any idea or alternative way yo convert from xml to Json

    // XML Data Format
    JaxbDataFormat xmlDataFormat = new JaxbDataFormat();
    JAXBContext con = JAXBContext.newInstance(Employee.class);
    **xmlDataFormat.setContext(con);**

    // JSON Data Format
    JacksonDataFormat jsonDataFormat = new JacksonDataFormat(Employee.class);

    from("file:C:/inputFolder").doTry().unmarshal(xmlDataFormat).
    process(new MyProcessor()).marshal(jsonDataFormat).
    to("jms:queue:javainuse").doCatch(Exception.class).process(new Processor() {
                public void process(Exchange exchange) throws Exception {
                    Exception cause = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, Exception.class);
                    System.out.println(cause);
                }
            });

Thanks!

Avis
  • 1
  • 4

1 Answers1

1

You can't find this function because either you aren't importing this package:

import org.apache.camel.converter.jaxb.JaxbDataFormat;

or because you aren't adding this dependency in your pom.xml:

 <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-jaxb</artifactId>
        <version>${camel-version}</version>
 </dependency>

You can check my reference archive here https://metiago.github.io/dev/2017/02/12/java-apache-camel-xml.html?query=camel for a better example.

Tiago R.
  • 36
  • 1
  • 3
  • You can do something like this JAXBContext con = JAXBContext.newInstance(Employee.class); JaxbDataFormat xmlDataFormat = new JaxbDataFormat(con); so your IDE can import the correct package. :) Camel contains two JaxbDataFormat packages and auto import fetches the wrong one... at least in my case. – Jakab Robert Jul 12 '21 at 12:24