Conditional validation of format or required property in Beanio

时间:2015-11-12 11:37:38

标签: spring formatting field conditional bean-io

I have a requirement to conditionally validate the format or required=true/false based another fields in a beanmapper configuration. Example:

<stream name="stream1" format="fixedlength" minlength="101" maxlength="101">
  <record name="record1" class="a.b.c.SomeClassName">
    <field name="updateType" required="true" length="1" regex="A|C" />
    <field name="firstName" required=? length="50" format=?/>
    <field name="lastName" required=? length="50" format=?/>
  </record>
</stream>

Condition scenario 1: for updateType="A", I need firstName to have not null ( not all spaces as this is a fixed length format record) and for updateType="C", firstName must be all blanks.

Condition scenario 2: for firstName=some value, lastName must also have some value (non blank)

How can I achieve this in Beanio? I am using spring-batch 3x for my job execution.

1 个答案:

答案 0 :(得分:0)

我无法获得任何BeanIO实用程序,开箱即用。我现在处理此问题的方法是在spring批处理器中执行这些条件验证。