fixed expression issue of json path mapping #122

This commit is contained in:
Francis Dong
2021-04-16 15:51:30 +08:00
committed by dxfeng10
parent b7385ab640
commit 9c72aa0787
3 changed files with 33 additions and 6 deletions

View File

@@ -23,6 +23,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
import java.util.stream.Collectors;
import org.noear.snack.ONode;
@@ -38,6 +39,9 @@ import we.util.MapUtil;
*/
public class PathMapping {
private static List<String> typeList = Arrays.asList("Integer", "int", "Boolean", "boolean", "Float", "float",
"Double", "double", "String", "string", "Long", "long");
public static ONode toONode(Object obj) {
ONode o = null;
synchronized (obj) {
@@ -116,10 +120,10 @@ public class PathMapping {
for (Entry<String, Object> entry : rules.entrySet()) {
if (entry.getValue() instanceof String) {
String val = (String) entry.getValue();
String[] vals = val.split(" ");
if (vals.length > 1) {
rs.put(entry.getKey(), vals[1]);
types.put(entry.getKey(), vals[0]);
Optional<String> optType = typeList.stream().filter(s -> val.startsWith(s + " ")).findFirst();
if (optType.isPresent()) {
rs.put(entry.getKey(), val.substring(optType.get().length() + 1));
types.put(entry.getKey(), optType.get());
} else {
rs.put(entry.getKey(), val);
}
@@ -160,7 +164,8 @@ public class PathMapping {
obj = val.val().isNull() ? null : val.val().getDouble();
break;
}
case "String": {
case "String":
case "string": {
obj = val.val().isNull() ? null : val.val().getString();
break;
}