RESOLVED - issue BATCH-1448: BeanWrapperFieldSetMapper should throw BindException (so the errors can be accessed)
This commit is contained in:
@@ -17,10 +17,8 @@
|
||||
package org.springframework.batch.item.file.mapping;
|
||||
|
||||
import java.beans.PropertyEditor;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
@@ -38,8 +36,8 @@ import org.springframework.beans.factory.BeanFactoryAware;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
import org.springframework.validation.BindException;
|
||||
import org.springframework.validation.DataBinder;
|
||||
import org.springframework.validation.ObjectError;
|
||||
|
||||
/**
|
||||
* {@link FieldSetMapper} implementation based on bean property paths. The
|
||||
@@ -159,27 +157,20 @@ public class BeanWrapperFieldSetMapper<T> extends DefaultPropertyEditorRegistrar
|
||||
* Map the {@link FieldSet} to an object retrieved from the enclosing Spring
|
||||
* context, or to a new instance of the required type if no prototype is
|
||||
* available.
|
||||
*
|
||||
* @throws NotWritablePropertyException if the {@link FieldSet} contains a
|
||||
* field that cannot be mapped to a bean property.
|
||||
* @throws BindingException if there is a type conversion or other error (if
|
||||
* @throws BindException if there is a type conversion or other error (if
|
||||
* the {@link DataBinder} from {@link #createBinder(Object)} has errors
|
||||
* after binding).
|
||||
*
|
||||
* @throws NotWritablePropertyException if the {@link FieldSet} contains a
|
||||
* field that cannot be mapped to a bean property.
|
||||
* @see org.springframework.batch.item.file.mapping.FieldSetMapper#mapFieldSet(FieldSet)
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public T mapFieldSet(FieldSet fs) {
|
||||
public T mapFieldSet(FieldSet fs) throws BindException {
|
||||
T copy = getBean();
|
||||
DataBinder binder = createBinder(copy);
|
||||
binder.bind(new MutablePropertyValues(getBeanProperties(copy, fs.getProperties())));
|
||||
if (binder.getBindingResult().hasErrors()) {
|
||||
List<ObjectError> errors = binder.getBindingResult().getAllErrors();
|
||||
List<String> messages = new ArrayList<String>(errors.size());
|
||||
for (ObjectError error : errors) {
|
||||
messages.add(error.getDefaultMessage());
|
||||
}
|
||||
throw new BindingException("" + messages);
|
||||
throw new BindException(binder.getBindingResult());
|
||||
}
|
||||
return copy;
|
||||
}
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.batch.item.file.mapping;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
public class BindingException extends RuntimeException {
|
||||
|
||||
/**
|
||||
* @param msg
|
||||
*/
|
||||
public BindingException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.springframework.batch.item.file.mapping;
|
||||
|
||||
import org.springframework.batch.item.file.transform.FieldSet;
|
||||
import org.springframework.validation.BindException;
|
||||
|
||||
|
||||
|
||||
@@ -34,6 +35,7 @@ public interface FieldSetMapper<T> {
|
||||
* Method used to map data obtained from a {@link FieldSet} into an object.
|
||||
*
|
||||
* @param fieldSet the {@link FieldSet} to map
|
||||
* @throws BindException if there is a problem with the binding
|
||||
*/
|
||||
T mapFieldSet(FieldSet fieldSet);
|
||||
T mapFieldSet(FieldSet fieldSet) throws BindException;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user