public class ValidatingItemProcessor<T> extends java.lang.Object implements ItemProcessor<T,T>, org.springframework.beans.factory.InitializingBean
ItemProcessor
that validates input and
returns it without modifications. Should the given Validator
throw a
ValidationException
this processor will re-throw it to indicate the
item should be skipped, unless setFilter(boolean)
is set to
true
, in which case null
will be returned to
indicate the item should be filtered.Constructor and Description |
---|
ValidatingItemProcessor()
Default constructor
|
ValidatingItemProcessor(Validator<? super T> validator)
Creates a ValidatingItemProcessor based on the given Validator.
|
Modifier and Type | Method and Description |
---|---|
void |
afterPropertiesSet() |
T |
process(T item)
Validate the item and return it unmodified
|
void |
setFilter(boolean filter)
Should the processor filter invalid records instead of skipping them?
|
void |
setValidator(Validator<? super T> validator)
Set the validator used to validate each item.
|
public void setValidator(Validator<? super T> validator)
validator
- the Validator
instance to be used.public void setFilter(boolean filter)
filter
- if set to true
, items that fail validation are filtered
(null
is returned). Otherwise, a ValidationException
will be
thrown.@Nullable public T process(T item) throws ValidationException
process
in interface ItemProcessor<T,T>
item
- to be processed, never null
.ValidationException
- if validation failspublic void afterPropertiesSet() throws java.lang.Exception
afterPropertiesSet
in interface org.springframework.beans.factory.InitializingBean
java.lang.Exception