Skip to content

Commit

Permalink
反序列化支持正则,解决string的反序列问题
Browse files Browse the repository at this point in the history
  • Loading branch information
wmz46 committed Jun 23, 2020
1 parent 7c2106d commit f78b655
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/main/java/com/iceolive/xpathmapper/XPathMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,10 @@ private static Object getObject(XPath xPath, Class<?> type, String str) {
if (!StringUtil.isEmpty(str)) {
if (type.isAssignableFrom(boolean.class) || type.isAssignableFrom(Boolean.class)) {
val = StringUtil.parseBoolean(str, xPath.trueString(), xPath.falseString(), type);
} else {
} else if(StringUtil.isNotEmpty(xPath.regex())) {
str = StringUtil.matchOne(str,xPath.regex(),1);
val = StringUtil.parse(str,xPath.format(),type);
}else{
val = StringUtil.parse(str, xPath.format(), type);
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/com/iceolive/xpathmapper/annotation/XPath.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,10 @@
String trueString() default "true";

String falseString() default "false";

/**
* 正则,反序列化时取第一个group
* @return
*/
String regex() default "";
}
2 changes: 2 additions & 0 deletions src/main/java/com/iceolive/xpathmapper/util/ReflectUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ public static boolean isBasicType(Class<?> clazz){
return true;
}else if(isDateType(clazz)){
return true;
}else if(clazz.isAssignableFrom(String.class)){
return true;
}
return false;
}
Expand Down

0 comments on commit f78b655

Please sign in to comment.