Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  * Copyright 2006-2007 the original author or authors.
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * See the License for the specific language governing permissions and
 * limitations under the License.
package org.springframework.batch.item.validator;
Simple implementation of org.springframework.batch.item.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.

Robert Kasanicky
public class ValidatingItemProcessor<T> implements ItemProcessor<T, T>, InitializingBean {
	private Validator<? super T> validator;
	private boolean filter = false;

Default constructor

Creates a ValidatingItemProcessor based on the given Validator.
	public ValidatingItemProcessor(Validator<? super T> validator) {
		this. = validator;

Set the validator used to validate each item.

	public void setValidator(Validator<? super T> validator) {
		this. = validator;

Should the processor filter invalid records instead of skipping them?

	public void setFilter(boolean filter) {
		this. = filter;

Validate the item and return it unmodified

the input item
ValidationException if validation fails
	public T process(T itemthrows ValidationException {
		try {
		catch (ValidationException e) {
			if () {
				return null// filter the item
			else {
				throw e// skip the item
		return item;
	public void afterPropertiesSet() throws Exception {
		Assert.notNull("Validator must not be null.");
New to GrepCode? Check out our FAQ X