diff --git a/CHANGELOG.md b/CHANGELOG.md index d157fe8e9..9d44a4d0e 100644 --- a/CHANGELOG.md +++ b/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) ------------------------------------------------------------------------------------------------------------- diff --git a/hutool-http/src/main/java/cn/hutool/http/server/SimpleServer.java b/hutool-http/src/main/java/cn/hutool/http/server/SimpleServer.java index f62141613..8af896aad 100644 --- a/hutool-http/src/main/java/cn/hutool/http/server/SimpleServer.java +++ b/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; } diff --git a/hutool-http/src/main/java/cn/hutool/http/server/handler/package-info.java b/hutool-http/src/main/java/cn/hutool/http/server/handler/package-info.java new file mode 100644 index 000000000..9c88626c2 --- /dev/null +++ b/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; \ No newline at end of file diff --git a/hutool-http/src/test/java/cn/hutool/http/server/SimpleServerTest.java b/hutool-http/src/test/java/cn/hutool/http/server/SimpleServerTest.java index bca649874..fc06d0db8 100644 --- a/hutool-http/src/test/java/cn/hutool/http/server/SimpleServerTest.java +++ b/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(); } } diff --git a/hutool-json/src/main/java/cn/hutool/json/JSONUtil.java b/hutool-json/src/main/java/cn/hutool/json/JSONUtil.java index 3afa65cc2..1715f9a4e 100644 --- a/hutool-json/src/main/java/cn/hutool/json/JSONUtil.java +++ b/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 {// 对象