Skip to content

Commit

Permalink
refs #71 リストの具象クラスを指定した場合の読み込みをサポートする。
Browse files Browse the repository at this point in the history
  • Loading branch information
mygreen committed Mar 11, 2016
1 parent 946e701 commit 0477524
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -41,13 +42,18 @@ public List toObject(final Cell cell, final FieldAdaptor adaptor, final XlsMappe
String cellValue = POIUtils.getCellContents(cell, config.getCellFormatter());
cellValue = Utils.getDefaultValueIfEmpty(cellValue, converterAnno);

Class<?> fieldClass = adaptor.getTargetClass();

Class<?> itemClass = anno.itemClass();
if(itemClass == Object.class) {
itemClass = adaptor.getLoadingGenericClassType();
}

try {
final List list = convertList(cellValue, itemClass, converterAnno, anno, config);
List list = convertList(cellValue, itemClass, converterAnno, anno, config);
if(List.class.isAssignableFrom(fieldClass)) {
list = (List) Utils.convertListToCollection(list, (Class<Collection>)fieldClass, config.getBeanFactory());
}
return list;
} catch(NumberFormatException e) {
throw newTypeBindException(e, cell, adaptor, cellValue)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.gh.mygreen.xlsmapper.cellconvert.converter;

import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
Expand Down Expand Up @@ -37,13 +38,16 @@ public Set toObject(final Cell cell, final FieldAdaptor adaptor, final XlsMapper
final ListCellConverter converter = new ListCellConverter();
final XlsArrayConverter anno = converter.getLoadingAnnotation(adaptor);

Class<?> fieldClass = adaptor.getTargetClass();

Class<?> itemClass = anno.itemClass();
if(itemClass == Object.class) {
itemClass = adaptor.getLoadingGenericClassType();
}

final List<?> list = converter.toObject(cell, adaptor, config);
return new LinkedHashSet(list);
Set<?> set = (Set) Utils.convertListToCollection(list, (Class<Collection>)fieldClass, config.getBeanFactory());
return set;
}

@Override
Expand Down

0 comments on commit 0477524

Please sign in to comment.