BeanIO - 抽象 class 或 class 实现接口的集合

BeanIO - Collection of abstract class or class implementing interface

是否可以使用 BeanIO 注释将字段定义为抽象 class 的集合,或者 class 实现接口的集合?

我要的是这个:

@Record(minOccurs = 1, maxOccurs = -1, collection = List.class)
List<SomeInterface> records;

然后我向集合提供不同具体 classes 的列表,其中都包含用于定义有效记录的所有注释。

但是我收到一条错误消息

Repeating segments without any child field component must have minOccurs=maxOccurs

...哪一种违背了目的。

我尝试过的一些东西:

编辑:这是我的配置:

  StreamFactory factory = StreamFactory.newInstance();
  StreamBuilder builder = new StreamBuilder("MyStreamName")
                .writeOnly()
                .format("delimited")
                .parser(new DelimitedParserBuilder(','))
                .addGroup(Parent.class);
  factory.define(builder);

...而 Parent.class 包含 List 记录;

从逻辑上讲,应该有一些东西将 SomeInterface 绑定到接口的具体实现,以便 BeanIO 可以弄清楚要做什么,但我似乎无法弄清楚如何设置此连接。

以下对我有用:

import org.beanio.annotation.Record;

@Record(name = "parentRecord", maxOccurs = 1, minOccurs = 1, collection = List.class)
public class Parent {

  @Record(minOccurs = 1, collection = List.class, name = "recordList")
  private List<A> records;

  // getter + setter
}

Parent class 现在是 @Record,需要将 StreamBuilder 更改为

final StreamFactory factory = StreamFactory.newInstance();
final StreamBuilder builder = new StreamBuilder("MyStreamName")
  .writeOnly()
  .format("delimited")
  .parser(new DelimitedParserBuilder(','))
  .addRecord(Parent.class);
factory.define(builder);

这对我来说没有任何例外