1 Reply Latest reply on Nov 17, 2019 10:49 PM by cfang

    BeanIO Reader with Validation

    richardmoore

      My bean has annotations for a field to not be null. It works -

       

      2019-11-11 14:38:41.860 jberet-1                                  jberet - WARN  JBERET000028: Failed to serialize exception: javax.validation.ConstraintViolationException:

      org.apache.bval.jsr.ConstraintDescriptorImpl@4c3ee7cf

      com.awginc.rpe.map.bean.RPEThrdPrtyDlsInputAllFldsMap@2ea27f55

      com.awginc.rpe.map.bean.RPEThrdPrtyDlsInputAllFldsMap@2ea27f55

      allowance2

      null

      Allowance2 is required

       

       

      The problem is I want to catch this as a read error and let the errorHandler take care of it so I can keep processing the file. What am I doing wrong?

       

      <chunk item-count="100">

      <reader ref="beanIOItemReader">

      <properties>

      <property name="resource" value="RPE_ThirdPartyDealsScan.csv" />

      <property name="streamName" value="ThrdPrtyDlsInputAllFlds" />

      <property name="streamMapping" value="ThrdPrtyDlsInputAllFlds.xml" />

      <property name="errorHandler" value="com.awginc.rpe.map.bean.DealScanBeanErrorHandler" />

      </properties>

      </reader>

      <writer ref="jsonItemWriter">

      <properties>

      <property name="resource" value="BusinessInformation.json" />

      <property name="writeMode" value="overwrite" />

      </properties>

      </writer>

      </chunk>

        • 1. Re: BeanIO Reader with Validation
          cfang

          sorry for the delay.  I think what happens is the BeanIO's BeanReader reads a record, which returns an object, and this object is passed to the bean validation for checking constraints.  So the validation part happens outside BeanIO's BeanReader's read method, and hence any BeanIO errorHandler will not have an effecet on bean validation errors.  Basically, the errorHandler you're using in this case is a BeanIO construct, not one in batch/jberet.

           

          For more details, you can check the source code of org.jberet.support.io.BeanIOItemReader