我目前正在将 Camel 从
3.2.0
升级到 3.18.0
。
在
3.17.0
版本中,camel-beanio
已被删除 (https://camel.apache.org/manual/camel-3x-upgrade-guide-3_17.html)。
我在 https://camel.apache.org/manual 上没有看到它为什么被删除,也没有看到如何替换它。
我知道我可以在我的
camel-beanio
中声明 pom.xml
的依赖关系,但我不想有 3.18.0
的驼峰版本和 3.16.0
的驼峰 beanio。
有什么线索吗?
谢谢
没有更换组件。没有人维护该项目 github.com/beanio/beanio 你最后一次提交是在大约 7 个月前,你可以使用
xml > jaxb
csv -> apache commons csv
一个选项可以是扁平包装。它似乎不支持 XML,但您仍然可以编组/解组平面文件。请参阅Camel 文档。 骆驼bindy也许是一个选择。
如果你确实需要使用 beanio,你可以选择 beanio 3,在 Lee Gilbert 的帖子中提到,并将其包装成自定义数据格式以便与 Camel 一起使用。 示例可以是:
<dependency>
<groupId>com.github.beanio</groupId>
<artifactId>beanio</artifactId>
<version>3.0.0.M3</version>
</dependency>
public class BeanIODataFormat<T> extends DefaultDataFormat {
private final StreamFactory factory = StreamFactory.newInstance();
private final String streamName;
private Class<T> destinationClass;
private int skip;
public BeanIODataFormat(String definition, int skip, Class<T> clazz, String streamName) {
this.skip = skip;
this.streamName = streamName;
factory.load(definition);
this.destinationClass = clazz;
}
public BeanIODataFormat(String definition, String streamName) {
this(definition, 0, null, streamName);
}
@Override
public void marshal(Exchange exchange, Object graph, OutputStream stream) {
Collection<T> collection = convertType(exchange, graph, Collection.class);
Writer writer = convertType(exchange, stream, Writer.class);
try (BeanWriter out = factory.createWriter(this.streamName, writer)) {
collection.stream()
.map(entry -> convertType(exchange, entry, destinationClass))
.forEach(out::write);
}
}
@Override
public Object unmarshal(Exchange exchange, InputStream stream) {
Reader reader = convertType(exchange, stream, Reader.class);
BeanReader beanReader = factory.createReader(this.streamName, reader);
beanReader.skip(skip);
Iterator<Article> result = Stream.generate(() -> (Article) beanReader.read())
.takeWhile(Objects::nonNull)
.iterator();
return result;
}
private static <T> T convertType(Exchange exchange, Object obj, Class<T> dest) {
try {
return exchange.getContext().getTypeConverter().mandatoryConvertTo(dest, obj);
} catch (NoTypeConversionAvailableException e) {
throw new RuntimeException(e);
}
}
public void setDestinationClass(Class<T> destinationClass) {
this.destinationClass = destinationClass;
}
public void setSkip(int skip) {
this.skip = skip;
}
}
然后在骆驼路线中使用
BeanIODataFormat<Article> dataFormat = new
BeanIODataFormat<>("path_to.beanio.xml", "articles");
dataFormat.setSkip(1);
dataFormat.setDestinationClass(Article.class);
from(...)
...
.unmarshal(dataFormat, false)
...
.marshal(dataFormat)
Beanio v3 分支位于 https://github.com/beanio/beanio Spring 框架支持在 v3 中被删除,没有关于camel-beanio 支持的评论。