mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
add HutoolJSONSerializer
This commit is contained in:
@@ -17,6 +17,8 @@
|
||||
package org.dromara.hutool.json.engine;
|
||||
|
||||
import org.dromara.hutool.core.text.StrUtil;
|
||||
import org.dromara.hutool.json.JSONObject;
|
||||
import org.dromara.hutool.json.JSONUtil;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@@ -39,4 +41,20 @@ public class JacksonTest {
|
||||
" \"gender\" : true\n" +
|
||||
"}", jsonString);
|
||||
}
|
||||
|
||||
/**
|
||||
* https://gitee.com/dromara/hutool/issues/IB3GM4<br>
|
||||
* JSON和Jackson兼容
|
||||
*/
|
||||
@Test
|
||||
void toJsonStringOfHutoolJsonTest() {
|
||||
final JSONObject jsonObject = JSONUtil.ofObj()
|
||||
.putValue("name", "张三")
|
||||
.putValue("age", 18)
|
||||
.putValue("sub", JSONUtil.ofObj()
|
||||
.putValue("aaa", "aa1").putValue("bbb", "bb1"));
|
||||
final JSONEngine engine = JSONEngineFactory.createEngine("jackson");
|
||||
final String jsonString = engine.toJsonString(jsonObject);
|
||||
Assertions.assertEquals("{\"name\":\"张三\",\"age\":18,\"sub\":{\"aaa\":\"aa1\",\"bbb\":\"bb1\"}}", jsonString);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user