Skip to content

Commit

Permalink
update the xls steps
Browse files Browse the repository at this point in the history
  • Loading branch information
ozlerhakan committed Nov 6, 2017
1 parent 8055200 commit 3278f66
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
11 changes: 5 additions & 6 deletions src/main/java/com/poiji/bind/mapping/HSSFUnmarshaller.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.apache.poi.ss.usermodel.Workbook;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;

Expand Down Expand Up @@ -61,8 +62,8 @@ public <T> List<T> unmarshal(Class<T> type) {
private <T> T deserialize0(Row currentRow, Class<T> type) {
T instance;
try {
instance = type.newInstance();
} catch (IllegalAccessException | InstantiationException e) {
instance = type.getDeclaredConstructor().newInstance();
} catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException | InstantiationException e) {
throw new PoijiInstantiationException("Cannot create a new instance of " + type.getName());
}

Expand All @@ -76,18 +77,16 @@ private <T> T tailSetFieldValue(Row currentRow, Class<? super T> type, T instanc
if (index != null) {
Class<?> fieldType = field.getType();
Cell cell = currentRow.getCell(index.value());
Object o;

if (!field.isAccessible())
field.setAccessible(true);

Object o;
if (cell != null) {
String value = dataFormatter.formatCellValue(cell);
o = Casting.castValue(fieldType, value, options);
} else {
o = Casting.castValue(fieldType, "", options);
}
try {
field.setAccessible(true);
field.set(instance, o);
} catch (IllegalAccessException e) {
throw new IllegalCastException("Unexpected cast type {" + o + "} of field" + field.getName());
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/com/poiji/bind/mapping/PoijiHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,10 @@ private void setValue(String content, Class<? super T> type, int column) {
Class<?> fieldType = field.getType();

if (column == index.value()) {

field.setAccessible(true);

Object o = Casting.castValue(fieldType, content, options);

try {
field.setAccessible(true);
field.set(instance, o);
} catch (IllegalAccessException e) {
throw new IllegalCastException("Unexpected cast type {" + o + "} of field" + field.getName());
Expand Down

0 comments on commit 3278f66

Please sign in to comment.