RESOLVED - issue BATCH-1361: PassThroughFieldExtractor does not handle Maps
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
package org.springframework.batch.item.file.transform;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* {@link FieldExtractor} that just returns the original item. If the item is an
|
||||
@@ -28,6 +29,20 @@ import java.util.Collection;
|
||||
public class PassThroughFieldExtractor<T> implements FieldExtractor<T> {
|
||||
|
||||
/**
|
||||
* Get an array of fields as close as possible to the input. The result
|
||||
* depends on the type of the input:
|
||||
* <ul>
|
||||
* <li>A {@link FieldSet} or array will be returned as is</li>
|
||||
* <li>For a Collection the <code>toArray()</code> method will be used</li>
|
||||
* <li>For a Map the <code>values()</code> will be returned as an array</li>
|
||||
* <li>Otherwise it is wrapped in a single element array.</li>
|
||||
* </ul>
|
||||
* Note that no attempt is made to sort the values, so passing in an
|
||||
* unordered collection or map is probably a bad idea. Spring often gives
|
||||
* you an ordered Map (e.g. if extracting data from a generic query using
|
||||
* JDBC), so check the documentation for whatever is being used to generate
|
||||
* the input.
|
||||
*
|
||||
* @param item the object to convert
|
||||
* @return an array of objects as close as possible to the original item
|
||||
*/
|
||||
@@ -41,6 +56,10 @@ public class PassThroughFieldExtractor<T> implements FieldExtractor<T> {
|
||||
return ((Collection<?>) item).toArray();
|
||||
}
|
||||
|
||||
if (item instanceof Map<?, ?>) {
|
||||
return ((Map<?, ?>) item).values().toArray();
|
||||
}
|
||||
|
||||
if (item instanceof FieldSet) {
|
||||
return ((FieldSet) item).getValues();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user