title: Why Does This Apache Camel Route Not Convert JSON to XML?
body: <p>I am trying to convert some JSON to XML using an Apache Camel route. Below is the code with the route in it, listing 1. The code that calls this code is the second source code segment, listing 2. The JSON that I want to convert to XML is in listing 3. The XML that is created from the Apache Camel route is is in listing 4. The XML that is actually created is not the JSON data though. <strong>Does anyone know how I can transform the JSON to XML with Apache Camel?</strong> </p>
  
  <pre><code>package org.hai;
  
  import org.apache.camel.builder.RouteBuilder;
  
  /**
   * A Camel Java DSL Router
   */
  public class MyRouteBuilder extends RouteBuilder {
  
      /**
       * Let's configure the Camel routing rules using Java code...
       */
      public void configure() {
  
          // Changes JSON data found in folder to XML - (hopefully) 
          from("file:src/data?noop=true").marshal().xstream().to("file:target/messages/others");
      }
  
  }
  </code></pre>
  
  <p>Listing 1: Apache Camel Route To Change JSON to XML</p>
  
  <pre><code>package org.hai;
  
  import org.apache.camel.main.Main;
  
  /**
   * A Camel Application
   */
  public class MainApp {
  
      /**
       * A main() so we can easily run these routing rules in our IDE
       */
      public static void main(String... args) throws Exception {
          Main main = new Main();
          main.enableHangupSupport();
          main.addRouteBuilder(new MyRouteBuilder());
          main.run(args);
  
          Thread.sleep(5000);
  
          System.exit(1);
      }
  
  }
  </code></pre>
  
  <p>Listing 2: The code that calls the Apache Camel route. </p>
  
  <pre><code>{
      "glossary": {
          "title": "example glossary",
          "GlossDiv": {
              "title": "S",
              "GlossList": {
                  "GlossEntry": {
                      "ID": "SGML",
                      "SortAs": "SGML",
                      "GlossTerm": "Standard Generalized Markup Language",
                      "Acronym": "SGML",
                      "Abbrev": "ISO 8879:1986",
                      "GlossDef": {
                          "para": "A meta-markup language, used to create markup languages such as DocBook.",
                          "GlossSeeAlso": ["GML", "XML"]
                      },
                      "GlossSee": "markup"
                  }
              }
          }
      }
  }
  </code></pre>
  
  <p>Listing 3: JSON to be transformed to XML </p>
  
  <pre><code>&lt;?xml version='1.0' encoding='UTF-8'?&gt;
  &lt;org.apache.camel.component.file.GenericFile&gt;
  &lt;endpointPath&gt;src/data&lt;/endpointPath&gt;
  &lt;fileName&gt;example.xml&lt;/fileName&gt;
  &lt;fileNameOnly&gt;example.xml&lt;/fileNameOnly&gt;
  &lt;relativeFilePath&gt;example.xml&lt;/relativeFilePath&gt;
  &lt;absoluteFilePath&gt;/home/captainkyle/Desktop/MavenPractice/transformer2/src/data/example.xml&lt;/absoluteFilePath&gt;
  &lt;fileLength&gt;583&lt;/fileLength&gt;
  &lt;lastModified&gt;1434061793000&lt;/lastModified&gt;
  &lt;file class="file"&gt;src/data/example.xml&lt;/file&gt;
  &lt;binding class="org.apache.camel.component.file.FileBinding"/&gt;
  &lt;absolute&gt;false&lt;/absolute&gt;
  &lt;directory&gt;false&lt;/directory&gt;
  &lt;/org.apache.camel.component.file.GenericFile&gt;
  </code></pre>
  
  <p>Listing 4: The XML created from the above Camel route. </p>
  
  <p>Thank-you for reading this. </p>
  
  <p>Regards,</p>