fix json.parse bug #1363

This commit is contained in:
Looly 2021-01-07 17:09:16 +08:00
parent 1deed5d9cf
commit 0800ffe1e5
5 changed files with 16 additions and 2 deletions

View File

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

View File

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

View File

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

View File

@ -45,6 +45,10 @@ public class SimpleServerTest {
response.write(request.getMultipart().getParamMap().toString(), ContentType.TEXT_PLAIN.toString()); 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(); .start();
} }
} }

View File

@ -218,7 +218,7 @@ public final class JSONUtil {
json = (JSON) obj; json = (JSON) obj;
} else if (obj instanceof CharSequence) { } else if (obj instanceof CharSequence) {
final String jsonStr = StrUtil.trim((CharSequence) obj); 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)) {// 列表 } else if (obj instanceof Iterable || obj instanceof Iterator || ArrayUtil.isArray(obj)) {// 列表
json = new JSONArray(obj, config); json = new JSONArray(obj, config);
} else {// 对象 } else {// 对象