fixed expression issue of json path mapping #122
This commit is contained in:
@@ -1,3 +1,20 @@
|
||||
/*
|
||||
* Copyright (C) 2021 the original author or authors.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package we.util;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
@@ -9,6 +26,11 @@ import java.util.Map;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Francis Dong
|
||||
*
|
||||
*/
|
||||
public class MapUtilTests {
|
||||
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user