Reputation: 2802
I have the following code, which I have taken from the Apache Camel web site:
XmlJsonDataFormat xmlJsonFormat = new XmlJsonDataFormat();
xmlJsonFormat.setEncoding("UTF-8");
xmlJsonFormat.setForceTopLevelObject(true);
xmlJsonFormat.setTrimSpaces(true);
xmlJsonFormat.setRootName("newRoot");
xmlJsonFormat.setSkipNamespaces(true);
xmlJsonFormat.setRemoveNamespacePrefixes(true);
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 from
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?
Upvotes: 2
Views: 3824
Reputation: 89
You need to add the following dependency in your pom.xml file. I think this 2 dependency is fine, 1.camel-jackson 2.xom
Upvotes: -2
Reputation: 55525
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.
Upvotes: 6