Camel route: read xml in pojo and write it back to xml file

I’ve come off for some time, but since there are many configuration files in xml, it is difficult to find the answers to my question.

What would I like to do? Using the caml route, I want to read in an XML file and put it in a POJO. Here I want to analyze this. In the end, I want to write another xml file (POJO) as an answer to an external folder.

My problem is that I don’t know how to tell a camel to parse the body of the xml file in my POJO.

A short example of what I did until I found out:

My camel route:

from("file:data/in")
                    .marshal().xstream()
                    .bean(XmlToBeanAndBackBean.class)
                    .unmarshal().xstream()
                    .to("file:data/out");

My POJO:

@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class XmlFilePojo {

     @XmlAnyAttribute
     private String name;
     @XmlElement(name = "the_age")
     private int theAge;

     public void setName(String name) {
         this.name = name;
     }
}

And my Bean, which is used on the camel route:

@Component
public class XmlToBeanAndBackBean {

    public XmlFilePojo transformXmlObject(XmlFilePojo xmlFilePojo){
        XmlFilePojo returnPojo = xmlFilePojo;
        returnPojo.setName("merkur");
        return returnPojo;
    }
}

I think my error is on the camel path that the camel is trying to convert the XML file to an XmlFilePojo object.

, :

: org.apache.camel.InvalidPayloadException: : XmlFilePojo, : [B @659392cd : byte [] on: simple.xml. : , : byte [] : XmlFilePojo [B @659392cd. [simple.xml]. : [org.apache.camel.NoTypeConversionAvailableException - , : byte [] : XmlFilePojo [B @659392cd]

[] , , . , - .

+4
2

camel-jaxb xml ↔ pojo, JAXB POJO. bean, POJO.

from("file:data/in")
    .bean(XmlToBeanAndBackBean.class)
    .to("file:data/out");
+5

unmarshal json.

from("file:data/in")
.unmarshal().json(JsonLibrary.Jackson, XmlFilePojo.class)
.to("file:data/out");
0

All Articles