BeanIO 是否需要我提供 setter
Does BeanIO require I provide a setter
BeanIO 似乎要求我为我的字段提供设置器。这是必要的吗?我创建了一个 BeanIO 编写器,我只打算编写文件,并且每个字段都有 getter - 为什么我需要 setter?
如果您的 bean 仅打算 序列化 (即由 BeanWriter
使用),您可以将流声明为 mode="write"
。这将导致 BeanIO 查找 getter 而不是 setter。
reference guide 指出:
By default, a stream mapping can be used for both reading input streams and writing output streams, called readwrite
mode. Setting mode to read orwrite instead, respectively restricts usage to a BeanReader
or a BeanWriter
only, but relaxes some validations on the mapping configuration.
When mode
is set to read
, a bean class does not require getter methods.
When mode
is set to write
, a bean class may be abstract or an interface, and does not require setter methods.
BeanIO 似乎要求我为我的字段提供设置器。这是必要的吗?我创建了一个 BeanIO 编写器,我只打算编写文件,并且每个字段都有 getter - 为什么我需要 setter?
如果您的 bean 仅打算 序列化 (即由 BeanWriter
使用),您可以将流声明为 mode="write"
。这将导致 BeanIO 查找 getter 而不是 setter。
reference guide 指出:
By default, a stream mapping can be used for both reading input streams and writing output streams, called
readwrite
mode. Setting mode to read orwrite instead, respectively restricts usage to aBeanReader
or aBeanWriter
only, but relaxes some validations on the mapping configuration.When
mode
is set toread
, a bean class does not require getter methods.When
mode
is set towrite
, a bean class may be abstract or an interface, and does not require setter methods.