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

@@ -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 {

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;
}

View File

@@ -249,7 +249,7 @@
<dependency>
<groupId>org.noear</groupId>
<artifactId>snack3</artifactId>
<version>3.1.6.4</version>
<version>3.1.14</version>
</dependency>
<dependency>