我正在尝试使用 BeanIO 库编写一个固定宽度的文件。这是有问题的记录:@Recordopen class KeySegment( @Field(at = 0, length = 1, required = true) var recordType: String = "", @Field(at = 1, length = 6, required = true) var primaryCorpId: String = "", @Field(at = 7, length = 16, minOccurs = 0) var creditCardAcc: String? = null, @Field(at = 7, length = 8, minOccurs = 0) var companyId: String? = null, @Field(at = 15, length = 8, minOccurs = 0) var sublevelId: String? = null, @Field(at = 23, length = 8, required = true) var fileCreateDate: String = "", @Field(at = 31, length = 8) var sourceId: String = "", @Field(at = 39, length = 816) var filler: String = "")请注意,creditCardAcc并companyId + sublevelId在文件中保持相同的位置。根据用例,我们设置creditCardAccfield 或companyIdand sublevelId。现在对于我的用例,我想设置creditCardAcc,但问题是companyId和sublevelId被空格填充并覆盖creditCardAcc字段,即使它们被设置为null。一种解决方案是将这些字段拉入两个子类 extendingKeySegment和 marshal 子类。但是,我想知道是否有更好的本机解决方案可用于实现此目的。例如,如果字段为空,是否有办法禁用填充?谢谢。
添加回答
举报
0/150
提交
取消