diff --git a/README.md b/README.md
index b78686c..74a3ea6 100644
--- a/README.md
+++ b/README.md
@@ -6,7 +6,7 @@
com.iceolive
xpathmapper
- 1.2.3
+ 1.2.4
```
## 二、快速开始
diff --git a/pom.xml b/pom.xml
index 47079f9..918c984 100644
--- a/pom.xml
+++ b/pom.xml
@@ -10,7 +10,7 @@
com.iceolive
xpathmapper
- 1.2.3
+ 1.2.4
xpathmapper is a XML processor (XML parser + XML generator) written in Java
diff --git a/src/main/java/com/iceolive/xpathmapper/JsonPathMapper.java b/src/main/java/com/iceolive/xpathmapper/JsonPathMapper.java
index c99a4fb..8a89f1d 100644
--- a/src/main/java/com/iceolive/xpathmapper/JsonPathMapper.java
+++ b/src/main/java/com/iceolive/xpathmapper/JsonPathMapper.java
@@ -33,7 +33,11 @@ public static T parse(Object obj, Class clazz) {
private static T parse(Object obj, Class clazz, String format) {
if (ReflectUtil.isBasicType(clazz)) {
- return (T) StringUtil.parse(obj.toString(), format, clazz);
+ if (obj != null) {
+ return (T) StringUtil.parse(obj.toString(), format, clazz);
+ } else {
+ return null;
+ }
}
List fields = ReflectUtil.getAllFields(clazz);
T newObj = ReflectUtil.newInstance(clazz);
@@ -43,8 +47,8 @@ private static T parse(Object obj, Class clazz, String format) {
continue;
}
JSONField jsonField = field.getAnnotation(JSONField.class);
- String dateFormat ="";
- if(jsonField !=null && !StringUtil.isEmpty(jsonField.format())){
+ String dateFormat = "";
+ if (jsonField != null && !StringUtil.isEmpty(jsonField.format())) {
dateFormat = jsonField.format();
}
boolean isList = false;
@@ -113,9 +117,9 @@ private static T parse(Object obj, Class clazz, String format) {
ReflectUtil.setValue(newObj, field.getName(), values);
} else if (List.class.isAssignableFrom(currentObj.getClass())) {
- Object values = ReflectUtil.newInstance(field, ((List)currentObj).size());
- for (int i = 0; i < ((List)currentObj).size(); i++) {
- Object item = parse(((List)currentObj).get(i), type, dateFormat);
+ Object values = ReflectUtil.newInstance(field, ((List) currentObj).size());
+ for (int i = 0; i < ((List) currentObj).size(); i++) {
+ Object item = parse(((List) currentObj).get(i), type, dateFormat);
((List) values).add(item);
}
ReflectUtil.setValue(newObj, field.getName(), values);
@@ -143,8 +147,8 @@ private static T parse(Object obj, Class clazz, String format) {
ReflectUtil.setValue(newObj, field.getName(), values);
} else if (Set.class.isAssignableFrom(currentObj.getClass())) {
- Object values = ReflectUtil.newInstance(field,((Set)currentObj).size());
- for (Object c : (Set)currentObj) {
+ Object values = ReflectUtil.newInstance(field, ((Set) currentObj).size());
+ for (Object c : (Set) currentObj) {
Object item = parse(c, type, dateFormat);
((Set) values).add(item);
}
@@ -164,5 +168,5 @@ private static T parse(Object obj, Class clazz, String format) {
}
return newObj;
}
-
+
}