JAXB marshalling in Apache Camel

穿精又带淫゛_ 提交于 2019-12-08 04:13:29

问题


I am new to Apache camel and need to perform a task where i need to marshal an object to xml file. I am using the below code but it is not working. Here, foo.pojo is package where JAXB annotated classes are present

JaxbDataFormat jaxbDataFormat =  new JaxbDataFormat("foo.pojo");
from("direct:start").marshal(jaxbDataFormat).to("file:C:/Users/Anand.Jain/Desktop/hello/abc.xml").end();

Please help.


回答1:


Option 1: Configure the context path

JaxbDataFormat jaxbDataFormat =  new JaxbDataFormat("foo.pojo");

OptionFactory or jaxb.index file must be defined in the given package as explained here.

Option 2: Configure the class(es) to be bound

JAXBContext jaxbContext = JAXBContext.newInstance(MyAnnotatedClass.class);
JaxbDataFormat jaxbDataFormat = new JaxbDataFormat(jaxbContext);

I prefere Option 2.




回答2:


Option 1 is recently impossible as JaxbDataFormat(String) constructor is not available as you can see in official javadoc

Documentation seems to be outdated about this point.

EDIT: BE CAREFUL there's TWO JaxbDataFormat

I have understood: there's TWO jaxbDataFormat in camel ecosystem

  • one is in camel-core package org.apache.camel.model.dataformat
  • another in camel-jaxb package org.apache.camel.converter.jaxb


来源:https://stackoverflow.com/questions/26800182/jaxb-marshalling-in-apache-camel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!