mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix code
This commit is contained in:
@@ -16,6 +16,11 @@
|
||||
|
||||
package org.dromara.hutool.json.engine;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.alibaba.fastjson2.JSONWriter;
|
||||
import com.alibaba.fastjson2.writer.ObjectWriter;
|
||||
import org.dromara.hutool.core.lang.Console;
|
||||
import org.dromara.hutool.core.text.StrUtil;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -36,4 +41,19 @@ public class FastJSONTest {
|
||||
" \"gender\":true\n" +
|
||||
"}", jsonString);
|
||||
}
|
||||
|
||||
@Test
|
||||
void toStringTest() {
|
||||
final String jsonStr = "{\"name\":\"张三\",\"age\":18,\"birthday\":\"2020-01-01\"}";
|
||||
final JSONObject jsonObject = JSON.parseObject(jsonStr);
|
||||
final JSONWriter writer = JSONWriter.of();
|
||||
writer.setRootObject(jsonObject);
|
||||
writer.write(jsonObject);
|
||||
|
||||
final JSONWriter.Context context = writer.getContext();
|
||||
final ObjectWriter<?> objectWriter = context.getObjectWriter(jsonObject.getClass());
|
||||
Console.log(objectWriter.getClass());
|
||||
|
||||
writer.close();
|
||||
}
|
||||
}
|
||||
|
@@ -5,6 +5,7 @@ import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonParser;
|
||||
import org.dromara.hutool.json.JSONObject;
|
||||
import org.dromara.hutool.json.JSONUtil;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.openjdk.jmh.annotations.*;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@@ -34,15 +35,18 @@ public class JsonToStringJmh {
|
||||
@Benchmark
|
||||
public void gsonJmh() {
|
||||
final String jsonStr = gson.toString();
|
||||
Assertions.assertNotNull(jsonStr);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void hutoolJmh() {
|
||||
final String jsonStr = hutoolJSON.toString();
|
||||
Assertions.assertNotNull(jsonStr);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void fastJSONJmh() {
|
||||
final String jsonStr = fastJSON.toString();
|
||||
Assertions.assertNotNull(jsonStr);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user