Adam Davies Adam Davies - 1 year ago 84
JSON Question

Apache Camel XmlJsonDataFormat XML to JSON

I have the following code, which I have taken from the Apache Camel web site:

XmlJsonDataFormat xmlJsonFormat = new XmlJsonDataFormat();
xmlJsonFormat.setExpandableProperties(Arrays.asList("d", "e"));

// from XML to JSON
from("direct:marshal").marshal(xmlJsonFormat).to("mock:json"); // 1

At the last line (marked 1), I get a compile error. I don't understand where the
method is coming from; there are no static imports, and I've looked through the examples and the postings on this site.

I don't know anything about Camel, and want to run this as a stand alone utility class for doing simple xml -> json conversions.

Can anyone help me understand what I have to do to make this snippet work. Failing that, does anyone know of a simple xml to json converter?

Answer Source

A good idea to get started with Camel is to walk throught this getting started guide

Also reading this article that excellent explain Camel in a 5 minute read is recommended

Then you would know that the from is from a Camel route, and that you need to use a RouteBuilder class to use it.