我正在尝试使用驼峰绑定将管道分隔的字符串数据转换为 xml。但它正在生成标签和类名。我还想将命名空间添加到我的标签中。
我尝试使用 Camel 流程生成自定义标签,但它不起作用。
ConverterRoute.java
private static final String SOURCE_INPUT_PATH = "file://inbox?fileName=3000.txt";
private static final String SOURCE_OUTPUT_PATH = "file://outbox?fileName=itemfile.xml";
public void addRoutesToCamelContext(CamelContext context) throws Exception {
context.addRoutes(new RouteBuilder() {
public void configure() {
try {
DataFormat bindyFixed = new BindyCsvDataFormat(PartInboundIFD.class);
NameSpace nameSpace = new NameSpace("PART_INB_IFD","https://apache.org.com");
from(SOURCE_INPUT_PATH).
unmarshal(bindyFixed).
marshal().
xstream().
to(SOURCE_OUTPUT_PATH);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
}
Pojo.java
@CsvRecord(separator = "\\|",skipField = true)
public class Pojo {
@Link
private ControlSegment CONTROL_SEGMENT;
}
CamelComponent.java
public class CamelConfig extends RouteBuilder {
@Override
public void configure() throws Exception {
try {
CamelContext context = new DefaultCamelContext();
ConverterRoute route = new ConverterRoute();
route.addRoutesToCamelContext(context);
context.start();
Thread.sleep(5000);
context.stop();
} catch (Exception exe) {
exe.printStackTrace();
}
}
}
输出 结果.xml
<list>
<com.abc.domain.Pojo>
<CONTROL__SEGMENT/>
<TRNNAM>PART_TRAN</TRNNAM>
<TRNVER>9.0</TRNVER>
</com.abc.domain.Pojo>
</list>
上面发布的是给定转换的输出。在第一个标签中,它打印带有整个包和类名的标签名称(例如:com.abc.domain.Pojo)。另外,我正在尝试生成名称空间,但它不会生成该名称空间在我的输出中。
慕哥6287543
相关分类