Skip to content

Commit

Permalink
support wrapper classes of primitive types
Browse files Browse the repository at this point in the history
  • Loading branch information
ozlerhakan committed Jun 21, 2018
1 parent 5478264 commit ece372b
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
6 changes: 3 additions & 3 deletions README.adoc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
= Poiji
:version: v1.11
:version: v1.12

image:https://travis-ci.org/ozlerhakan/poiji.svg?branch=master["Build Status", link="https://travis-ci.org/ozlerhakan/poiji"] image:https://api.codacy.com/project/badge/Grade/6587e90886184da29a1b7c5634695c9d["Codacy code quality", link="https://www.codacy.com/app/ozlerhakan/poiji?utm_source=github.com&utm_medium=referral&utm_content=ozlerhakan/poiji&utm_campaign=Badge_Grade"] image:https://coveralls.io/repos/github/ozlerhakan/poiji/badge.svg?branch=master["Coverage Status", link="https://coveralls.io/github/ozlerhakan/poiji?branch=master"] image:https://img.shields.io/badge/license-MIT-blue.svg[]

Expand All @@ -23,7 +23,7 @@ In your Maven/Gradle project, first add the corresponding dependency:
[source,groovy]
----
dependencies {
compile 'com.github.ozlerhakan:poiji:1.11'
compile 'com.github.ozlerhakan:poiji:1.12'
}
----

Expand Down Expand Up @@ -76,7 +76,7 @@ public class Employee {
----
<1> As of 1.10, optionally we can access the index of each row item by using the `ExcelRow` annotation. Annotated variable should be of type `int`, `double`, `float` or `long`.
<2> A field must be annotated with `@ExcelCell` along with its property in order to get the value from the right coordinate in the target excel sheet.
<3> An annotated field can be either protected, private or public modifier. The field may be either of `boolean`, `int`, `long`, `float`, `double`, `java.util.Date` or `String`.
<3> An annotated field can be either protected, private or public modifier. The field may be either of `boolean`, `int`, `long`, `float`, `double`, or their wrapper classes. You can add a field of `java.util.Date` or `String`.

This is the excel file (`employees.xlsx`) we want to map to a list of `Employee` instance:

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.github.ozlerhakan</groupId>
<artifactId>poiji</artifactId>
<version>1.11</version>
<version>1.12</version>
<packaging>jar</packaging>

<name>poiji</name>
Expand Down
13 changes: 7 additions & 6 deletions src/main/java/com/poiji/util/Casting.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,23 +70,24 @@ private Date dateValue(String value, PoijiOptions options) {

public Object castValue(Class<?> fieldType, String value, PoijiOptions options) {
Object o;
if (fieldType.getName().equals("int")) {
if (fieldType.getName().equals("int") || fieldType.getName().equals("java.lang.Integer")) {
o = integerValue(Objects.equals(value, "") ? "0" : value);

} else if (fieldType.getName().equals("long")) {
} else if (fieldType.getName().equals("long") || fieldType.getName().equals("java.lang.Long")) {
o = longValue(Objects.equals(value, "") ? "0" : value);

} else if (fieldType.getName().equals("double")) {
} else if (fieldType.getName().equals("double") || fieldType.getName().equals("java.lang.Double")) {
o = doubleValue(Objects.equals(value, "") ? "0" : value);

} else if (fieldType.getName().equals("float")) {
} else if (fieldType.getName().equals("float") || fieldType.getName().equals("java.lang.Float")) {
o = floatValue(Objects.equals(value, "") ? "0" : value);

} else if (fieldType.getName().equals("boolean")) {
} else if (fieldType.getName().equals("boolean") || fieldType.getName().equals("java.lang.Boolean")) {
o = Boolean.valueOf(value);
} else if (fieldType.getName().equals("java.util.Date")) {

} else if (fieldType.getName().equals("java.util.Date")) {
o = dateValue(value, options);

} else
o = value;
return o;
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/com/poiji/deserialize/model/byid/Employee.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class Employee {
protected String surname;

@ExcelCell(3)
protected int age;
protected Integer age;

@ExcelCell(4)
protected boolean single;
Expand Down Expand Up @@ -83,7 +83,7 @@ public String toString() {
"employeeId=" + employeeId +
", name='" + name + '\'' +
", surname='" + surname + '\'' +
", age=" + age +
", age=" + (age == null ? 0 : age) +
", single=" + single +
", birthday='" + birthday + '\'' +
'}';
Expand Down

0 comments on commit ece372b

Please sign in to comment.