Browse Source

fix json.parse bug #1363

Looly 5 years ago
parent
commit
0800ffe1e5

+ 2 - 1
CHANGELOG.md

@@ -3,7 +3,7 @@
 
 -------------------------------------------------------------------------------------------------------------
 
-# 5.5.7 (2021-01-06)
+# 5.5.7 (2021-01-07)
 
 ### 新特性
 * 【core   】     DynaBean.create增加重载方法(pr#245@Gitee)
@@ -18,6 +18,7 @@
 
 ### Bug修复
 * 【core   】     修复CsvReader读取双引号未转义问题(issur#I2BMP1@Gitee)
+* 【json   】     JSONUtil.parse修复config无效问题(issur#1363@Github)
 
 -------------------------------------------------------------------------------------------------------------
 

+ 5 - 0
hutool-http/src/main/java/cn/hutool/http/server/SimpleServer.java

@@ -2,6 +2,8 @@ package cn.hutool.http.server;
 
 import cn.hutool.core.io.IORuntimeException;
 import cn.hutool.core.lang.Console;
+import cn.hutool.core.thread.GlobalThreadPool;
+import cn.hutool.core.util.StrUtil;
 import cn.hutool.http.server.action.Action;
 import cn.hutool.http.server.action.RootAction;
 import cn.hutool.http.server.handler.ActionHandler;
@@ -53,6 +55,7 @@ public class SimpleServer {
 		} catch (IOException e) {
 			throw new IORuntimeException(e);
 		}
+		setExecutor(GlobalThreadPool.getExecutor());
 	}
 
 	/**
@@ -63,6 +66,8 @@ public class SimpleServer {
 	 * @return this
 	 */
 	public SimpleServer addHandler(String path, HttpHandler handler) {
+		// 非/开头的路径会报错
+		path = StrUtil.addPrefixIfNot(path, StrUtil.SLASH);
 		this.server.createContext(path, handler);
 		return this;
 	}

+ 4 - 0
hutool-http/src/main/java/cn/hutool/http/server/handler/package-info.java

@@ -0,0 +1,4 @@
+/**
+ * {@link com.sun.net.httpserver.HttpHandler} 实现包装
+ */
+package cn.hutool.http.server.handler;

+ 4 - 0
hutool-http/src/test/java/cn/hutool/http/server/SimpleServerTest.java

@@ -45,6 +45,10 @@ public class SimpleServerTest {
 							response.write(request.getMultipart().getParamMap().toString(), ContentType.TEXT_PLAIN.toString());
 						}
 				)
+				.addAction("test/zeroStr", (req, res)->{
+					res.addHeader("Content-Length", "0".length() + "");
+					res.write("0");
+				})
 				.start();
 	}
 }

+ 1 - 1
hutool-json/src/main/java/cn/hutool/json/JSONUtil.java

@@ -218,7 +218,7 @@ public final class JSONUtil {
 			json = (JSON) obj;
 		} else if (obj instanceof CharSequence) {
 			final String jsonStr = StrUtil.trim((CharSequence) obj);
-			json = StrUtil.startWith(jsonStr, '[') ? parseArray(jsonStr) : parseObj(jsonStr);
+			json = isJsonArray(jsonStr) ? parseArray(jsonStr, config) : parseObj(jsonStr, config);
 		} else if (obj instanceof Iterable || obj instanceof Iterator || ArrayUtil.isArray(obj)) {// 列表
 			json = new JSONArray(obj, config);
 		} else {// 对象