mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix code
This commit is contained in:
@@ -32,7 +32,7 @@ public class CustomSerializeTest {
|
||||
public void init() {
|
||||
SerializerManager.getInstance().register(CustomBean.class,
|
||||
(JSONSerializer<CustomBean>) (bean, context) ->
|
||||
((OldJSONObject)context.getContextJson()).set("customName", bean.name));
|
||||
((JSONObject)context.getContextJson()).set("customName", bean.name));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -40,7 +40,7 @@ public class CustomSerializeTest {
|
||||
final CustomBean customBean = new CustomBean();
|
||||
customBean.name = "testName";
|
||||
|
||||
final OldJSONObject obj = JSONUtil.parseObj(customBean);
|
||||
final JSONObject obj = JSONUtil.parseObj(customBean);
|
||||
Assertions.assertEquals("testName", obj.getStr("customName"));
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ public class CustomSerializeTest {
|
||||
final CustomBean customBean = new CustomBean();
|
||||
customBean.name = "testName";
|
||||
|
||||
final OldJSONObject obj = JSONUtil.ofObj().set("customBean", customBean);
|
||||
final JSONObject obj = JSONUtil.ofObj().set("customBean", customBean);
|
||||
Assertions.assertEquals("testName", obj.getJSONObject("customBean").getStr("customName"));
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ public class CustomSerializeTest {
|
||||
public void deserializeTest() {
|
||||
SerializerManager.getInstance().register(CustomBean.class, (JSONDeserializer<CustomBean>) (json, deserializeType) -> {
|
||||
final CustomBean customBean = new CustomBean();
|
||||
customBean.name = ((OldJSONObject) json).getStr("customName");
|
||||
customBean.name = ((JSONObject) json).getStr("customName");
|
||||
return customBean;
|
||||
});
|
||||
|
||||
|
@@ -71,7 +71,7 @@ public class Issue1101Test {
|
||||
"\t\"type\": 0\n" +
|
||||
"}";
|
||||
|
||||
final OldJSONObject jsonObject = JSONUtil.parseObj(json);
|
||||
final JSONObject jsonObject = JSONUtil.parseObj(json);
|
||||
|
||||
final TreeNode treeNode = JSONUtil.toBean(jsonObject, TreeNode.class);
|
||||
Assertions.assertEquals(2, treeNode.getChildren().size());
|
||||
|
@@ -30,7 +30,7 @@ public class Issue1200Test {
|
||||
|
||||
@Test
|
||||
public void toBeanTest() {
|
||||
final OldJSONObject jsonObject = JSONUtil.parseObj(
|
||||
final JSONObject jsonObject = JSONUtil.parseObj(
|
||||
ResourceUtil.readUtf8Str("issue1200.json"),
|
||||
JSONConfig.of().setIgnoreError(true));
|
||||
|
||||
|
@@ -28,7 +28,7 @@ import java.sql.SQLException;
|
||||
public class Issue1399Test {
|
||||
@Test
|
||||
void sqlExceptionTest() {
|
||||
final OldJSONObject set = JSONUtil.ofObj().set("error", new SQLException("test"));
|
||||
final JSONObject set = JSONUtil.ofObj().set("error", new SQLException("test"));
|
||||
Assertions.assertEquals("{\"error\":\"java.sql.SQLException: test\"}", set.toString());
|
||||
}
|
||||
}
|
||||
|
@@ -35,7 +35,7 @@ public class Issue2090Test {
|
||||
final TestBean test = new TestBean();
|
||||
test.setLocalDate(LocalDate.now());
|
||||
|
||||
final OldJSONObject json = JSONUtil.parseObj(test);
|
||||
final JSONObject json = JSONUtil.parseObj(test);
|
||||
final TestBean test1 = json.toBean(TestBean.class);
|
||||
Assertions.assertEquals(test, test1);
|
||||
}
|
||||
@@ -43,14 +43,14 @@ public class Issue2090Test {
|
||||
@Test
|
||||
public void parseLocalDateTest(){
|
||||
final LocalDate localDate = LocalDate.now();
|
||||
final OldJSONObject jsonObject = JSONUtil.parseObj(localDate);
|
||||
final JSONObject jsonObject = JSONUtil.parseObj(localDate);
|
||||
Assertions.assertNotNull(jsonObject.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void toBeanLocalDateTest(){
|
||||
final LocalDate d = LocalDate.now();
|
||||
final OldJSONObject obj = JSONUtil.parseObj(d);
|
||||
final JSONObject obj = JSONUtil.parseObj(d);
|
||||
final LocalDate d2 = obj.toBean(LocalDate.class);
|
||||
Assertions.assertEquals(d, d2);
|
||||
}
|
||||
@@ -58,7 +58,7 @@ public class Issue2090Test {
|
||||
@Test
|
||||
public void toBeanLocalDateTimeTest(){
|
||||
final LocalDateTime d = LocalDateTime.now();
|
||||
final OldJSONObject obj = JSONUtil.parseObj(d);
|
||||
final JSONObject obj = JSONUtil.parseObj(d);
|
||||
final LocalDateTime d2 = obj.toBean(LocalDateTime.class);
|
||||
Assertions.assertEquals(d, d2);
|
||||
}
|
||||
@@ -66,14 +66,14 @@ public class Issue2090Test {
|
||||
@Test
|
||||
public void toBeanLocalTimeTest(){
|
||||
final LocalTime d = LocalTime.now();
|
||||
final OldJSONObject obj = JSONUtil.parseObj(d);
|
||||
final JSONObject obj = JSONUtil.parseObj(d);
|
||||
final LocalTime d2 = obj.toBean(LocalTime.class);
|
||||
Assertions.assertEquals(d, d2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void monthTest(){
|
||||
final OldJSONObject jsonObject = new OldJSONObject();
|
||||
final JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.set("month", Month.JANUARY);
|
||||
Assertions.assertEquals("{\"month\":1}", jsonObject.toString());
|
||||
}
|
||||
|
@@ -42,7 +42,7 @@ public class Issue2131Test {
|
||||
Stream.of(apple, pear).forEach(collections::add);
|
||||
|
||||
final String jsonStr = JSONUtil.toJsonStr(goodsResponse);
|
||||
final OldJSONObject jsonObject = JSONUtil.parseObj(jsonStr);
|
||||
final JSONObject jsonObject = JSONUtil.parseObj(jsonStr);
|
||||
|
||||
final GoodsResponse result = jsonObject.toBean(GoodsResponse.class);
|
||||
Assertions.assertEquals(0, result.getCollections().size());
|
||||
|
@@ -25,7 +25,7 @@ public class Issue2507Test {
|
||||
@Test
|
||||
public void xmlToJsonTest(){
|
||||
final String xml = "<MsgInfo> <Msg> <![CDATA[<msg><body><row action=\"select\"><DIET>低盐饮食[嘱托]]><![CDATA[]</DIET></row></body></msg>]]> </Msg> <Msg> <![CDATA[<msg><body><row action=\"select\"><DIET>流质饮食</DIET></row></body></msg>]]> </Msg> </MsgInfo>";
|
||||
final OldJSONObject jsonObject = JSONUtil.xmlToJson(xml);
|
||||
final JSONObject jsonObject = JSONUtil.xmlToJson(xml);
|
||||
|
||||
assertEquals("{\"MsgInfo\":{\"Msg\":[\"<msg><body><row action=\\\"select\\\"><DIET>低盐饮食[嘱托\",\"]</DIET></row></body></msg>\",\"<msg><body><row action=\\\"select\\\"><DIET>流质饮食</DIET></row></body></msg>\"]}}"
|
||||
, jsonObject.toString());
|
||||
|
@@ -57,7 +57,7 @@ public class Issue2555Test {
|
||||
public static class MySerializer implements JSONSerializer<MyType> {
|
||||
@Override
|
||||
public JSON serialize(final MyType bean, final JSONContext context) {
|
||||
return ((OldJSONObject)context.getContextJson()).set("addr", bean.getAddress());
|
||||
return ((JSONObject)context.getContextJson()).set("addr", bean.getAddress());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ public class Issue2555Test {
|
||||
@Override
|
||||
public MyType deserialize(final JSON json, final Type deserializeType) {
|
||||
final MyType myType = new MyType();
|
||||
myType.setAddress(((OldJSONObject)json).getStr("addr"));
|
||||
myType.setAddress(((JSONObject)json).getStr("addr"));
|
||||
return myType;
|
||||
}
|
||||
}
|
||||
|
@@ -32,7 +32,7 @@ public class Issue2572Test {
|
||||
public void putDayOfWeekTest(){
|
||||
final Set<DayOfWeek> weeks = new HashSet<>();
|
||||
weeks.add(DayOfWeek.MONDAY);
|
||||
final OldJSONObject obj = new OldJSONObject();
|
||||
final JSONObject obj = new JSONObject();
|
||||
obj.set("weeks", weeks);
|
||||
Assertions.assertEquals("{\"weeks\":[1]}", obj.toString());
|
||||
|
||||
@@ -45,7 +45,7 @@ public class Issue2572Test {
|
||||
public void putMonthTest(){
|
||||
final Set<Month> months = new HashSet<>();
|
||||
months.add(Month.DECEMBER);
|
||||
final OldJSONObject obj = new OldJSONObject();
|
||||
final JSONObject obj = new JSONObject();
|
||||
obj.set("months", months);
|
||||
Assertions.assertEquals("{\"months\":[12]}", obj.toString());
|
||||
|
||||
@@ -58,7 +58,7 @@ public class Issue2572Test {
|
||||
public void putMonthDayTest(){
|
||||
final Set<MonthDay> monthDays = new HashSet<>();
|
||||
monthDays.add(MonthDay.of(Month.DECEMBER, 1));
|
||||
final OldJSONObject obj = new OldJSONObject();
|
||||
final JSONObject obj = new JSONObject();
|
||||
obj.set("monthDays", monthDays);
|
||||
Assertions.assertEquals("{\"monthDays\":[\"--12-01\"]}", obj.toString());
|
||||
|
||||
|
@@ -43,7 +43,7 @@ public class Issue2749Test {
|
||||
final String jsonStr = JSONUtil.toJsonStr(map);
|
||||
|
||||
@SuppressWarnings("MismatchedQueryAndUpdateOfCollection")
|
||||
final OldJSONObject jsonObject = new OldJSONObject(jsonStr);
|
||||
final JSONObject jsonObject = JSONUtil.parseObj(jsonStr);
|
||||
Assertions.assertNotNull(jsonObject);
|
||||
|
||||
// 栈溢出
|
||||
|
@@ -22,7 +22,7 @@ import org.junit.jupiter.api.Test;
|
||||
public class Issue2801Test {
|
||||
@Test
|
||||
public void toStringTest() {
|
||||
final OldJSONObject recordObj = new OldJSONObject(JSONConfig.of().setIgnoreNullValue(false));
|
||||
final JSONObject recordObj = new JSONObject(JSONConfig.of().setIgnoreNullValue(false));
|
||||
recordObj.put("m_reportId", null);
|
||||
Assertions.assertEquals("{\"m_reportId\":null}", recordObj.toString());
|
||||
}
|
||||
|
@@ -23,7 +23,7 @@ public class Issue2953Test {
|
||||
@Test
|
||||
public void parseObjWithBigNumberTest() {
|
||||
final String a = "{\"a\": 114793903847679990000000000000000000000}";
|
||||
final OldJSONObject jsonObject = JSONUtil.parseObj(a, JSONConfig.of());
|
||||
final JSONObject jsonObject = JSONUtil.parseObj(a, JSONConfig.of());
|
||||
Assertions.assertEquals("{\"a\":\"114793903847679990000000000000000000000\"}", jsonObject.toString());
|
||||
}
|
||||
}
|
||||
|
@@ -24,7 +24,7 @@ public class Issue3051Test {
|
||||
|
||||
@Test
|
||||
public void parseTest() {
|
||||
final OldJSONObject jsonObject = JSONUtil.parseObj(new EmptyBean(),
|
||||
final JSONObject jsonObject = JSONUtil.parseObj(new EmptyBean(),
|
||||
JSONConfig.of().setIgnoreError(true));
|
||||
|
||||
Assertions.assertEquals("{}", jsonObject.toString());
|
||||
@@ -33,7 +33,7 @@ public class Issue3051Test {
|
||||
@Test
|
||||
public void parseTest2() {
|
||||
Assertions.assertThrows(JSONException.class, ()->{
|
||||
final OldJSONObject jsonObject = JSONUtil.parseObj(new EmptyBean());
|
||||
final JSONObject jsonObject = JSONUtil.parseObj(new EmptyBean());
|
||||
Assertions.assertEquals("{}", jsonObject.toString());
|
||||
});
|
||||
}
|
||||
|
@@ -70,9 +70,9 @@ public class Issue3086Test {
|
||||
public JSON serialize(final TestBean bean, final JSONContext context) {
|
||||
final List<String> strings = bean.getAuthorities()
|
||||
.stream().map(SimpleGrantedAuthority::getAuthority).collect(Collectors.toList());
|
||||
OldJSONObject contextJson = (OldJSONObject) context.getContextJson();
|
||||
JSONObject contextJson = (JSONObject) context.getContextJson();
|
||||
if(null == contextJson){
|
||||
contextJson = new OldJSONObject(context.config());
|
||||
contextJson = new JSONObject(context.config());
|
||||
}
|
||||
contextJson.set("authorities",strings);
|
||||
return contextJson;
|
||||
|
@@ -33,7 +33,7 @@ public class Issue3139Test {
|
||||
" </c>\n" +
|
||||
"</r>";
|
||||
|
||||
final OldJSONObject jsonObject = XmlUtil.xmlToBean(XmlUtil.parseXml(xml).getDocumentElement(), OldJSONObject.class);
|
||||
final JSONObject jsonObject = XmlUtil.xmlToBean(XmlUtil.parseXml(xml).getDocumentElement(), JSONObject.class);
|
||||
final R bean = jsonObject.toBean(R.class);
|
||||
Assertions.assertNotNull(bean);
|
||||
|
||||
|
@@ -23,7 +23,7 @@ public class Issue3193Test {
|
||||
@Test
|
||||
void parseTest() {
|
||||
final String jsonStr = "{\"desc\":\"测试数据\\\\\"}";
|
||||
final OldJSONObject parse = JSONUtil.parseObj(jsonStr);
|
||||
final JSONObject parse = JSONUtil.parseObj(jsonStr);
|
||||
Assertions.assertEquals("测试数据\\", parse.getStr("desc"));
|
||||
}
|
||||
}
|
||||
|
@@ -24,7 +24,7 @@ import org.junit.jupiter.api.Test;
|
||||
public class Issue3274Test {
|
||||
@Test
|
||||
public void toBeanTest() {
|
||||
final OldJSONObject entries = new OldJSONObject("{\n" +
|
||||
final JSONObject entries = JSONUtil.parseObj("{\n" +
|
||||
" \n" +
|
||||
" \"age\": 36,\n" +
|
||||
" \"gender\": \"\",\n" +
|
||||
|
@@ -24,7 +24,7 @@ public class Issue3619Test {
|
||||
public void parseObjTest() {
|
||||
final String json = "{\"@timestamp\":\"2024-06-14T00:02:06.438Z\",\"@version\":\"1\",\"int_arr\":[-4]}";
|
||||
final JSONConfig jsonConfig = JSONConfig.of().setKeyComparator(String.CASE_INSENSITIVE_ORDER);
|
||||
final OldJSONObject jsonObject = JSONUtil.parseObj(json, jsonConfig);
|
||||
final JSONObject jsonObject = JSONUtil.parseObj(json, jsonConfig);
|
||||
|
||||
final String jsonStr = jsonObject.toJSONString(0, pair -> {
|
||||
final Object key = pair.getKey();
|
||||
|
@@ -33,7 +33,7 @@ public class Issue644Test {
|
||||
final BeanWithDate beanWithDate = new BeanWithDate();
|
||||
beanWithDate.setDate(LocalDateTime.now());
|
||||
|
||||
final OldJSONObject jsonObject = JSONUtil.parseObj(beanWithDate);
|
||||
final JSONObject jsonObject = JSONUtil.parseObj(beanWithDate);
|
||||
|
||||
BeanWithDate beanWithDate2 = JSONUtil.toBean(jsonObject, BeanWithDate.class);
|
||||
Assertions.assertEquals(TimeUtil.formatNormal(beanWithDate.getDate()),
|
||||
|
@@ -25,7 +25,7 @@ public class IssueI3EGJPTest {
|
||||
|
||||
@Test
|
||||
public void hutoolMapToBean() {
|
||||
final OldJSONObject paramJson = new OldJSONObject();
|
||||
final JSONObject paramJson = new JSONObject();
|
||||
paramJson.set("is_booleana", "1");
|
||||
paramJson.set("is_booleanb", true);
|
||||
final ConvertDO convertDO = BeanUtil.toBean(paramJson, ConvertDO.class);
|
||||
|
@@ -28,7 +28,7 @@ public class IssueI4RBZ4Test {
|
||||
public void sortTest(){
|
||||
final String jsonStr = "{\"id\":\"123\",\"array\":[1,2,3],\"outNum\":356,\"body\":{\"ava1\":\"20220108\",\"use\":1,\"ava2\":\"20230108\"},\"name\":\"John\"}";
|
||||
|
||||
final OldJSONObject jsonObject = JSONUtil.parseObj(jsonStr, JSONConfig.of().setNatureKeyComparator());
|
||||
final JSONObject jsonObject = JSONUtil.parseObj(jsonStr, JSONConfig.of().setNatureKeyComparator());
|
||||
Assertions.assertEquals("{\"array\":[1,2,3],\"body\":{\"ava1\":\"20220108\",\"ava2\":\"20230108\",\"use\":1},\"id\":\"123\",\"name\":\"John\",\"outNum\":356}", jsonObject.toString());
|
||||
}
|
||||
}
|
||||
|
@@ -22,7 +22,7 @@ import org.junit.jupiter.api.Test;
|
||||
public class IssueI59LW4Test {
|
||||
@Test
|
||||
public void bytesTest(){
|
||||
final OldJSONObject jsonObject = JSONUtil.ofObj().set("bytes", new byte[]{1});
|
||||
final JSONObject jsonObject = JSONUtil.ofObj().set("bytes", new byte[]{1});
|
||||
Assertions.assertEquals("{\"bytes\":[1]}", jsonObject.toString());
|
||||
|
||||
final byte[] bytes = jsonObject.getBytes("bytes");
|
||||
|
@@ -34,7 +34,7 @@ public class IssueI5DHK2Test {
|
||||
" }]\n" +
|
||||
"}";
|
||||
|
||||
final OldJSONObject json = JSONUtil.parseObj(jsonStr);
|
||||
final JSONObject json = JSONUtil.parseObj(jsonStr);
|
||||
final String exployerName = json
|
||||
.getJSONArray("punished_parties")
|
||||
.getJSONObject(0)
|
||||
|
@@ -18,6 +18,7 @@ package org.dromara.hutool.json;
|
||||
|
||||
import org.dromara.hutool.core.collection.ListUtil;
|
||||
import org.dromara.hutool.core.io.resource.ResourceUtil;
|
||||
import org.dromara.hutool.core.lang.Console;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@@ -28,7 +29,8 @@ public class IssueI5OMSCTest {
|
||||
|
||||
@Test
|
||||
public void filterTest(){
|
||||
final OldJSONObject json = JSONUtil.parseObj(ResourceUtil.readUtf8Str("issueI5OMSC.json"));
|
||||
final JSONObject json = JSONUtil.parseObj(ResourceUtil.readUtf8Str("issueI5OMSC.json"));
|
||||
Console.log(json.toStringPretty());
|
||||
|
||||
final String s = json.toJSONString(0, (entry) -> {
|
||||
final Object key = entry.getKey();
|
||||
|
@@ -28,7 +28,7 @@ import javax.xml.xpath.XPathConstants;
|
||||
public class IssueI676ITTest {
|
||||
@Test
|
||||
public void parseXMLTest() {
|
||||
final OldJSONObject jsonObject = JSONUtil.parseObj(ResourceUtil.readUtf8Str("issueI676IT.json"));
|
||||
final JSONObject jsonObject = JSONUtil.parseObj(ResourceUtil.readUtf8Str("issueI676IT.json"));
|
||||
final String xmlStr = JSONXMLSerializer.toXml(jsonObject, null, (String) null);
|
||||
final String content = String.valueOf(XPathUtil.getByXPath("/page/orderItems[1]/content", XmlUtil.readXml(xmlStr), XPathConstants.STRING));
|
||||
Assertions.assertEquals(content, "bar1");
|
||||
|
@@ -25,12 +25,11 @@ import java.util.AbstractMap;
|
||||
|
||||
public class IssueI6SZYBTest {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
void mutableEntryTest() {
|
||||
final MutableEntry<String, String> entry = MutableEntry.of("a", "b");
|
||||
final String jsonStr = JSONUtil.toJsonStr(entry);
|
||||
final MutableEntry<String, String> entry2 = JSONUtil.toBean(jsonStr, MutableEntry.class);
|
||||
final MutableEntry<String, String> entry2 = JSONUtil.toBean(jsonStr, new TypeReference<MutableEntry<String, String>>() {});
|
||||
|
||||
Assertions.assertEquals(entry, entry2);
|
||||
}
|
||||
@@ -45,22 +44,21 @@ public class IssueI6SZYBTest {
|
||||
Assertions.assertEquals(entry, entry2);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
void simpleEntryTest() {
|
||||
final AbstractMap.SimpleEntry<String, String> entry = new AbstractMap.SimpleEntry<>("a", "b");
|
||||
final String jsonStr = JSONUtil.toJsonStr(entry);
|
||||
final AbstractMap.SimpleEntry<String, String> entry2 = JSONUtil.toBean(jsonStr, AbstractMap.SimpleEntry.class);
|
||||
final AbstractMap.SimpleEntry<String, String> entry2 = JSONUtil.toBean(jsonStr, new TypeReference<AbstractMap.SimpleEntry<String, String>>() {});
|
||||
|
||||
Assertions.assertEquals(entry, entry2);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
void simpleEntryTest2() {
|
||||
final AbstractMap.SimpleEntry<String, String> entry = new AbstractMap.SimpleEntry<>("a", "b");
|
||||
final String jsonStr = JSONUtil.toJsonStr(entry);
|
||||
final MutableEntry<String, String> entry2 = JSONUtil.toBean(jsonStr, MutableEntry.class);
|
||||
final MutableEntry<String, String> entry2 = JSONUtil.toBean(jsonStr, new TypeReference<MutableEntry<String, String>>() {});
|
||||
|
||||
|
||||
Assertions.assertEquals(entry, entry2);
|
||||
}
|
||||
|
@@ -30,7 +30,7 @@ public class IssueI6YN2ATest {
|
||||
public void toBeanTest() {
|
||||
final String str = "{\"conditions\":{\"user\":\"test\",\"sex\":\"男\"}," +
|
||||
"\"headers\":{\"name\":\"姓名\",\"age\":\"年龄\",\"email\":\"邮箱\",\"number\":\"号码\",\"pwd\":\"密码\"}}";
|
||||
final OldJSONObject jsonObject = JSONUtil.parseObj(str);
|
||||
final JSONObject jsonObject = JSONUtil.parseObj(str);
|
||||
|
||||
final PageQuery<User> bean = jsonObject.toBean(new TypeReference<PageQuery<User>>() {});
|
||||
Assertions.assertEquals("{name=姓名, age=年龄, email=邮箱, number=号码, pwd=密码}", bean.headers.toString());
|
||||
|
@@ -26,7 +26,7 @@ public class IssueI76CSUTest {
|
||||
@Test
|
||||
void parseTest() {
|
||||
final String str = "{ \"card\": true, \"content\": \"【标题】\n摘要\", \"time\": 1678434181000}";
|
||||
final OldJSONObject entries = JSONUtil.parseObj(str);
|
||||
final JSONObject entries = JSONUtil.parseObj(str);
|
||||
Assertions.assertEquals("【标题】\n摘要", entries.getStr("content"));
|
||||
}
|
||||
}
|
||||
|
@@ -33,8 +33,8 @@ public class IssueI7VM64Test {
|
||||
final HashMap<String, Object> map = new HashMap<>();
|
||||
map.put("a", "1");
|
||||
|
||||
final OldJSONObject jsonObject = new OldJSONObject();
|
||||
jsonObject.put("c", map);
|
||||
final JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.set("c", map);
|
||||
map.put("b", 2);
|
||||
|
||||
//Console.log("Hutool JSON: " + jsonObject);
|
||||
|
@@ -30,7 +30,7 @@ public class IssueI90ADXTest {
|
||||
final TestBean testBean = new TestBean();
|
||||
testBean.name = "aaaa";
|
||||
|
||||
final OldJSONObject json = JSONUtil.parseObj(testBean);
|
||||
final JSONObject json = JSONUtil.parseObj(testBean);
|
||||
Assertions.assertEquals("{\"name\":\"aaaa\"}", json.toString());
|
||||
}
|
||||
|
||||
|
@@ -17,6 +17,7 @@
|
||||
package org.dromara.hutool.json;
|
||||
|
||||
import org.dromara.hutool.core.text.StrUtil;
|
||||
import org.dromara.hutool.json.mapper.JSONObjectMapper;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@@ -26,10 +27,12 @@ public class IssueI9DX5HTest {
|
||||
@Test
|
||||
void xmlToJSONTest() {
|
||||
final String xml = "<GoodMsg>你好</GoodMsg>";
|
||||
final OldJSONObject jsonObject = new OldJSONObject(xml, JSONConfig.of(), entry -> {
|
||||
final JSONObjectMapper mapper = JSONObjectMapper.of(xml, entry -> {
|
||||
entry.setKey(StrUtil.toUnderlineCase((CharSequence) entry.getKey()));
|
||||
return true;
|
||||
});
|
||||
final JSONObject jsonObject = new JSONObject();
|
||||
mapper.mapTo(jsonObject);
|
||||
|
||||
Assertions.assertEquals("{\"good_msg\":\"你好\"}", jsonObject.toString());
|
||||
}
|
||||
|
@@ -31,7 +31,7 @@ public class IssueI9HQQETest {
|
||||
final JSONConfig jsonConfig = new JSONConfig();
|
||||
jsonConfig.setDateFormat("dd/MM/yyyy");
|
||||
|
||||
final OldJSONObject entries = JSONUtil.parseObj(json, jsonConfig);
|
||||
final JSONObject entries = JSONUtil.parseObj(json, jsonConfig);
|
||||
|
||||
final MMHBo mmh = entries.toBean(MMHBo.class);
|
||||
Assertions.assertNotNull(mmh.getCurrentDate());
|
||||
|
@@ -23,7 +23,7 @@ public class IssueIAP4GMTest {
|
||||
@Test
|
||||
void parse() {
|
||||
final String res = "{\"uid\":\"asdf\\n\"}";
|
||||
final OldJSONObject entries = JSONUtil.parseObj(res);
|
||||
final JSONObject entries = JSONUtil.parseObj(res);
|
||||
Assertions.assertEquals("asdf\n", entries.getStr("uid"));
|
||||
}
|
||||
}
|
||||
|
@@ -33,7 +33,7 @@ public class IssuesI44E4HTest {
|
||||
public void deserializerTest(){
|
||||
SerializerManager.getInstance().register(TestDto.class, (JSONDeserializer<TestDto>) (json, deserializeType) -> {
|
||||
final TestDto testDto = new TestDto();
|
||||
testDto.setMd(new AcBizModuleMd("name1", ((OldJSONObject)json).getStr("md")));
|
||||
testDto.setMd(new AcBizModuleMd("name1", ((JSONObject)json).getStr("md")));
|
||||
return testDto;
|
||||
});
|
||||
|
||||
|
@@ -17,20 +17,21 @@
|
||||
package org.dromara.hutool.json;
|
||||
|
||||
import org.dromara.hutool.core.reflect.TypeReference;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class IssuesI4V14NTest {
|
||||
|
||||
@Test
|
||||
public void parseTest(){
|
||||
final String str = "{\"A\" : \"A\\nb\"}";
|
||||
final OldJSONObject jsonObject = JSONUtil.parseObj(str);
|
||||
Assertions.assertEquals("A\nb", jsonObject.getStr("A"));
|
||||
final JSONObject jsonObject = JSONUtil.parseObj(str);
|
||||
assertEquals("A\nb", jsonObject.getStr("A"));
|
||||
|
||||
final Map<String, String> map = jsonObject.toBean(new TypeReference<Map<String, String>>() {});
|
||||
Assertions.assertEquals("A\nb", map.get("A"));
|
||||
assertEquals("A\nb", map.get("A"));
|
||||
}
|
||||
}
|
||||
|
@@ -46,7 +46,7 @@ public class JSONArrayTest {
|
||||
@Test()
|
||||
public void createJSONArrayFromJSONObjectTest() {
|
||||
// JSONObject实现了Iterable接口,可以转换为JSONArray
|
||||
final OldJSONObject jsonObject = new OldJSONObject();
|
||||
final JSONObject jsonObject = new JSONObject();
|
||||
|
||||
JSONArray jsonArray = new JSONArray(jsonObject, JSONConfig.of());
|
||||
assertEquals(new JSONArray(), jsonArray);
|
||||
@@ -99,7 +99,7 @@ public class JSONArrayTest {
|
||||
public void readJSONArrayFromFileTest() {
|
||||
final JSONArray array = JSONUtil.readJSONArray(FileUtil.file("exam_test.json"), CharsetUtil.UTF_8);
|
||||
|
||||
final OldJSONObject obj0 = array.getJSONObject(0);
|
||||
final JSONObject obj0 = array.getJSONObject(0);
|
||||
final Exam exam = JSONUtil.toBean(obj0, Exam.class);
|
||||
assertEquals("0", exam.getAnswerArray()[0].getSeq());
|
||||
}
|
||||
@@ -318,7 +318,7 @@ public class JSONArrayTest {
|
||||
//noinspection MismatchedQueryAndUpdateOfCollection
|
||||
final JSONArray array = new JSONArray(jsonArr, null, (mutable) -> {
|
||||
if(mutable.getKey() instanceof Integer){
|
||||
final OldJSONObject o = (OldJSONObject) mutable.getValue();
|
||||
final JSONObject o = (JSONObject) mutable.getValue();
|
||||
if ("111".equals(o.getStr("id"))) {
|
||||
o.set("name", "test1_edit");
|
||||
}
|
||||
@@ -327,7 +327,7 @@ public class JSONArrayTest {
|
||||
});
|
||||
assertEquals(2, array.size());
|
||||
assertTrue(array.getJSONObject(0).containsKey("id"));
|
||||
assertEquals("test1_edit", array.getJSONObject(0).get("name"));
|
||||
assertEquals("test1_edit", array.getJSONObject(0).getObj("name"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -337,8 +337,8 @@ public class JSONArrayTest {
|
||||
array.add(JSONUtil.ofObj().set("name", "bbb"));
|
||||
array.add(JSONUtil.ofObj().set("name", "ccc"));
|
||||
|
||||
StringBuilder result = new StringBuilder();
|
||||
array.jsonIter(OldJSONObject.class).forEach(result::append);
|
||||
final StringBuilder result = new StringBuilder();
|
||||
array.jsonIter(JSONObject.class).forEach(result::append);
|
||||
assertEquals("{\"name\":\"aaa\"}{\"name\":\"bbb\"}{\"name\":\"ccc\"}", result.toString());
|
||||
}
|
||||
}
|
||||
|
@@ -70,10 +70,10 @@ public class JSONConvertTest {
|
||||
tempMap.put("userInfoDict", userInfoDict);
|
||||
tempMap.put("toSendManIdCard", 1);
|
||||
|
||||
final OldJSONObject obj = JSONUtil.parseObj(tempMap);
|
||||
final JSONObject obj = JSONUtil.parseObj(tempMap);
|
||||
Assertions.assertEquals(new Integer(1), obj.getInt("toSendManIdCard"));
|
||||
|
||||
final OldJSONObject examInfoDictsJson = obj.getJSONObject("userInfoDict");
|
||||
final JSONObject examInfoDictsJson = obj.getJSONObject("userInfoDict");
|
||||
Assertions.assertEquals(new Integer(1), examInfoDictsJson.getInt("id"));
|
||||
Assertions.assertEquals("质量过关", examInfoDictsJson.getStr("realName"));
|
||||
|
||||
@@ -90,7 +90,7 @@ public class JSONConvertTest {
|
||||
+ " {\n" + " \"id\": 3,\n" + " \"answerIs\": 0,\n" + " \"examType\": 1\n" + " }\n" + " ],\n" //
|
||||
+ " \"photoPath\": \"yx.mm.com\"\n" + " },\n" + " \"toSendManIdCard\": 1\n" + "}";
|
||||
|
||||
final OldJSONObject jsonObject = JSONUtil.parseObj(examJson).getJSONObject("examInfoDicts");
|
||||
final JSONObject jsonObject = JSONUtil.parseObj(examJson).getJSONObject("examInfoDicts");
|
||||
final UserInfoDict userInfoDict = jsonObject.toBean(UserInfoDict.class);
|
||||
|
||||
Assertions.assertEquals(userInfoDict.getId(), new Integer(1));
|
||||
@@ -99,7 +99,7 @@ public class JSONConvertTest {
|
||||
//============
|
||||
|
||||
final String jsonStr = "{\"id\":null,\"examInfoDict\":[{\"answerIs\":1, \"id\":null}]}";//JSONUtil.toJsonStr(userInfoDict1);
|
||||
final OldJSONObject jsonObject2 = JSONUtil.parseObj(jsonStr);//.getJSONObject("examInfoDicts");
|
||||
final JSONObject jsonObject2 = JSONUtil.parseObj(jsonStr);//.getJSONObject("examInfoDicts");
|
||||
final UserInfoDict userInfoDict2 = jsonObject2.toBean(UserInfoDict.class);
|
||||
Assertions.assertNull(userInfoDict2.getId());
|
||||
}
|
||||
@@ -110,7 +110,7 @@ public class JSONConvertTest {
|
||||
@Test
|
||||
public void testJson2Bean2() {
|
||||
final String jsonStr = ResourceUtil.readUtf8Str("evaluation.json");
|
||||
final OldJSONObject obj = JSONUtil.parseObj(jsonStr);
|
||||
final JSONObject obj = JSONUtil.parseObj(jsonStr);
|
||||
final PerfectEvaluationProductResVo vo = obj.toBean(PerfectEvaluationProductResVo.class);
|
||||
|
||||
Assertions.assertEquals(obj.getStr("HA001"), vo.getHA001());
|
||||
|
@@ -42,7 +42,7 @@ public class JSONDeserializerTest {
|
||||
|
||||
@Override
|
||||
public TestBean deserialize(final JSON json, final Type deserializeType) {
|
||||
final OldJSONObject valueObj = (OldJSONObject) json;
|
||||
final JSONObject valueObj = (JSONObject) json;
|
||||
this.name = valueObj.getStr("customName");
|
||||
this.address = valueObj.getStr("customAddress");
|
||||
return this;
|
||||
|
@@ -23,7 +23,7 @@ public class JSONNullTest {
|
||||
|
||||
@Test
|
||||
public void parseNullTest(){
|
||||
final OldJSONObject bodyjson = JSONUtil.parseObj("{\n" +
|
||||
final JSONObject bodyjson = JSONUtil.parseObj("{\n" +
|
||||
" \"device_model\": null,\n" +
|
||||
" \"device_status_date\": null,\n" +
|
||||
" \"imsi\": null,\n" +
|
||||
@@ -38,7 +38,7 @@ public class JSONNullTest {
|
||||
|
||||
@Test
|
||||
public void parseNullTest2(){
|
||||
final OldJSONObject bodyjson = JSONUtil.parseObj("{\n" +
|
||||
final JSONObject bodyjson = JSONUtil.parseObj("{\n" +
|
||||
" \"device_model\": null,\n" +
|
||||
" \"device_status_date\": null,\n" +
|
||||
" \"imsi\": null,\n" +
|
||||
|
@@ -51,7 +51,7 @@ public class JSONObjectTest {
|
||||
public void toStringTest() {
|
||||
final String str = "{\"code\": 500, \"data\":null}";
|
||||
//noinspection MismatchedQueryAndUpdateOfCollection
|
||||
final OldJSONObject jsonObject = new OldJSONObject(str);
|
||||
final JSONObject jsonObject = JSONUtil.parseObj(str, JSONConfig.of().setIgnoreNullValue(false));
|
||||
Assertions.assertEquals("{\"code\":500,\"data\":null}", jsonObject.toString());
|
||||
jsonObject.config().setIgnoreNullValue(true);
|
||||
Assertions.assertEquals("{\"code\":500}", jsonObject.toString());
|
||||
@@ -61,7 +61,7 @@ public class JSONObjectTest {
|
||||
public void toStringTest2() {
|
||||
final String str = "{\"test\":\"关于开展2018年度“文明集体”、“文明职工”评选表彰活动的通知\"}";
|
||||
//noinspection MismatchedQueryAndUpdateOfCollection
|
||||
final OldJSONObject json = new OldJSONObject(str);
|
||||
final JSONObject json = JSONUtil.parseObj(str);
|
||||
Assertions.assertEquals(str, json.toString());
|
||||
}
|
||||
|
||||
@@ -70,51 +70,51 @@ public class JSONObjectTest {
|
||||
*/
|
||||
@Test
|
||||
public void toStringTest3() {
|
||||
final OldJSONObject json = Objects.requireNonNull(JSONUtil.ofObj()//
|
||||
.set("dateTime", DateUtil.parse("2019-05-02 22:12:01")))//
|
||||
.setDateFormat(DatePattern.NORM_DATE_PATTERN);
|
||||
final JSONObject json = JSONUtil.ofObj(JSONConfig.of().setDateFormat(DatePattern.NORM_DATE_PATTERN))//
|
||||
.set("dateTime", DateUtil.parse("2019-05-02 22:12:01"));
|
||||
Assertions.assertEquals("{\"dateTime\":\"2019-05-02\"}", json.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void toStringWithDateTest() {
|
||||
OldJSONObject json = JSONUtil.ofObj().set("date", DateUtil.parse("2019-05-08 19:18:21"));
|
||||
JSONObject json = JSONUtil.ofObj().set("date", DateUtil.parse("2019-05-08 19:18:21"));
|
||||
assert json != null;
|
||||
Assertions.assertEquals("{\"date\":1557314301000}", json.toString());
|
||||
|
||||
json = Objects.requireNonNull(JSONUtil.ofObj().set("date", DateUtil.parse("2019-05-08 19:18:21"))).setDateFormat(DatePattern.NORM_DATE_PATTERN);
|
||||
json = JSONUtil.ofObj(JSONConfig.of().setDateFormat(DatePattern.NORM_DATE_PATTERN))
|
||||
.set("date", DateUtil.parse("2019-05-08 19:18:21"));
|
||||
Assertions.assertEquals("{\"date\":\"2019-05-08\"}", json.toString());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void putAllTest() {
|
||||
final OldJSONObject json1 = JSONUtil.ofObj()
|
||||
final JSONObject json1 = JSONUtil.ofObj()
|
||||
.set("a", "value1")
|
||||
.set("b", "value2")
|
||||
.set("c", "value3")
|
||||
.set("d", true);
|
||||
|
||||
final OldJSONObject json2 = JSONUtil.ofObj()
|
||||
final JSONObject json2 = JSONUtil.ofObj()
|
||||
.set("a", "value21")
|
||||
.set("b", "value22");
|
||||
|
||||
// putAll操作会覆盖相同key的值,因此a,b两个key的值改变,c的值不变
|
||||
json1.putAll(json2);
|
||||
|
||||
Assertions.assertEquals(json1.get("a"), "value21");
|
||||
Assertions.assertEquals(json1.get("b"), "value22");
|
||||
Assertions.assertEquals(json1.get("c"), "value3");
|
||||
Assertions.assertEquals(json1.getObj("a"), "value21");
|
||||
Assertions.assertEquals(json1.getObj("b"), "value22");
|
||||
Assertions.assertEquals(json1.getObj("c"), "value3");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseStringTest() {
|
||||
final String jsonStr = "{\"b\":\"value2\",\"c\":\"value3\",\"a\":\"value1\", \"d\": true, \"e\": null}";
|
||||
final OldJSONObject jsonObject = JSONUtil.parseObj(jsonStr);
|
||||
Assertions.assertEquals(jsonObject.get("a"), "value1");
|
||||
Assertions.assertEquals(jsonObject.get("b"), "value2");
|
||||
Assertions.assertEquals(jsonObject.get("c"), "value3");
|
||||
Assertions.assertEquals(jsonObject.get("d"), true);
|
||||
final JSONObject jsonObject = JSONUtil.parseObj(jsonStr);
|
||||
Assertions.assertEquals(jsonObject.getObj("a"), "value1");
|
||||
Assertions.assertEquals(jsonObject.getObj("b"), "value2");
|
||||
Assertions.assertEquals(jsonObject.getObj("c"), "value3");
|
||||
Assertions.assertEquals(jsonObject.getObj("d"), true);
|
||||
|
||||
Assertions.assertTrue(jsonObject.containsKey("e"));
|
||||
Assertions.assertNull(jsonObject.get("e"));
|
||||
@@ -124,7 +124,7 @@ public class JSONObjectTest {
|
||||
public void parseStringTest2() {
|
||||
final String jsonStr = "{\"file_name\":\"RMM20180127009_731.000\",\"error_data\":\"201121151350701001252500000032 18973908335 18973908335 13601893517 201711211700152017112115135420171121 6594000000010100000000000000000000000043190101701001910072 100001100 \",\"error_code\":\"F140\",\"error_info\":\"最早发送时间格式错误,该字段可以为空,当不为空时正确填写格式为“YYYYMMDDHHMISS”\",\"app_name\":\"inter-pre-check\"}";
|
||||
//noinspection MismatchedQueryAndUpdateOfCollection
|
||||
final OldJSONObject json = new OldJSONObject(jsonStr);
|
||||
final JSONObject json = JSONUtil.parseObj(jsonStr);
|
||||
Assertions.assertEquals("F140", json.getStr("error_code"));
|
||||
Assertions.assertEquals("最早发送时间格式错误,该字段可以为空,当不为空时正确填写格式为“YYYYMMDDHHMISS”", json.getStr("error_info"));
|
||||
}
|
||||
@@ -133,7 +133,7 @@ public class JSONObjectTest {
|
||||
public void parseStringTest3() {
|
||||
final String jsonStr = "{\"test\":\"体”、“文\"}";
|
||||
//noinspection MismatchedQueryAndUpdateOfCollection
|
||||
final OldJSONObject json = new OldJSONObject(jsonStr);
|
||||
final JSONObject json = JSONUtil.parseObj(jsonStr);
|
||||
Assertions.assertEquals("体”、“文", json.getStr("test"));
|
||||
}
|
||||
|
||||
@@ -141,8 +141,8 @@ public class JSONObjectTest {
|
||||
public void parseStringTest4() {
|
||||
final String jsonStr = "{'msg':'这里还没有内容','data':{'cards':[]},'ok':0}";
|
||||
//noinspection MismatchedQueryAndUpdateOfCollection
|
||||
final OldJSONObject json = new OldJSONObject(jsonStr);
|
||||
Assertions.assertEquals(new Integer(0), json.getInt("ok"));
|
||||
final JSONObject json = JSONUtil.parseObj(jsonStr);
|
||||
Assertions.assertEquals(Integer.valueOf(0), json.getInt("ok"));
|
||||
Assertions.assertEquals(new JSONArray(), json.getJSONObject("data").getJSONArray("cards"));
|
||||
}
|
||||
|
||||
@@ -150,8 +150,8 @@ public class JSONObjectTest {
|
||||
public void parseBytesTest() {
|
||||
final String jsonStr = "{'msg':'这里还没有内容','data':{'cards':[]},'ok':0}";
|
||||
//noinspection MismatchedQueryAndUpdateOfCollection
|
||||
final OldJSONObject json = new OldJSONObject(jsonStr.getBytes(StandardCharsets.UTF_8));
|
||||
Assertions.assertEquals(new Integer(0), json.getInt("ok"));
|
||||
final JSONObject json = JSONUtil.parseObj(jsonStr.getBytes(StandardCharsets.UTF_8));
|
||||
Assertions.assertEquals(Integer.valueOf(0), json.getInt("ok"));
|
||||
Assertions.assertEquals(new JSONArray(), json.getJSONObject("data").getJSONArray("cards"));
|
||||
}
|
||||
|
||||
@@ -161,8 +161,8 @@ public class JSONObjectTest {
|
||||
final StringReader stringReader = new StringReader(jsonStr);
|
||||
|
||||
//noinspection MismatchedQueryAndUpdateOfCollection
|
||||
final OldJSONObject json = new OldJSONObject(stringReader);
|
||||
Assertions.assertEquals(new Integer(0), json.getInt("ok"));
|
||||
final JSONObject json = JSONUtil.parseObj(stringReader);
|
||||
Assertions.assertEquals(Integer.valueOf(0), json.getInt("ok"));
|
||||
Assertions.assertEquals(new JSONArray(), json.getJSONObject("data").getJSONArray("cards"));
|
||||
}
|
||||
|
||||
@@ -172,8 +172,8 @@ public class JSONObjectTest {
|
||||
final ByteArrayInputStream in = new ByteArrayInputStream(jsonStr.getBytes(StandardCharsets.UTF_8));
|
||||
|
||||
//noinspection MismatchedQueryAndUpdateOfCollection
|
||||
final OldJSONObject json = new OldJSONObject(in);
|
||||
Assertions.assertEquals(new Integer(0), json.getInt("ok"));
|
||||
final JSONObject json = JSONUtil.parseObj(in);
|
||||
Assertions.assertEquals(Integer.valueOf(0), json.getInt("ok"));
|
||||
Assertions.assertEquals(new JSONArray(), json.getJSONObject("data").getJSONArray("cards"));
|
||||
}
|
||||
|
||||
@@ -182,15 +182,15 @@ public class JSONObjectTest {
|
||||
//在5.3.2之前,</div>中的/会被转义,修复此bug的单元测试
|
||||
final String jsonStr = "{\"a\":\"<div>aaa</div>\"}";
|
||||
//noinspection MismatchedQueryAndUpdateOfCollection
|
||||
final OldJSONObject json = new OldJSONObject(jsonStr);
|
||||
final JSONObject json = JSONUtil.parseObj(jsonStr);
|
||||
Assertions.assertEquals("<div>aaa</div>", json.getObj("a"));
|
||||
Assertions.assertEquals(jsonStr, json.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void toBeanTest() {
|
||||
final OldJSONObject subJson = JSONUtil.ofObj().set("value1", "strValue1").set("value2", "234");
|
||||
final OldJSONObject json = JSONUtil.ofObj(JSONConfig.of().setIgnoreError(true)).set("strValue", "strTest").set("intValue", 123)
|
||||
final JSONObject subJson = JSONUtil.ofObj().set("value1", "strValue1").set("value2", "234");
|
||||
final JSONObject json = JSONUtil.ofObj(JSONConfig.of().setIgnoreError(true)).set("strValue", "strTest").set("intValue", 123)
|
||||
// 测试空字符串转对象
|
||||
.set("doubleValue", "")
|
||||
.set("beanValue", subJson)
|
||||
@@ -209,7 +209,7 @@ public class JSONObjectTest {
|
||||
|
||||
@Test
|
||||
public void toBeanNullStrTest() {
|
||||
final OldJSONObject json = JSONUtil.ofObj(JSONConfig.of().setIgnoreError(true))//
|
||||
final JSONObject json = JSONUtil.ofObj(JSONConfig.of().setIgnoreError(true))//
|
||||
.set("strValue", "null")//
|
||||
.set("intValue", 123)//
|
||||
// 子对象对应"null"字符串,如果忽略错误,跳过,否则抛出转换异常
|
||||
@@ -231,7 +231,7 @@ public class JSONObjectTest {
|
||||
userA.setDate(new Date());
|
||||
userA.setSqs(ListUtil.of(new Seq("seq1"), new Seq("seq2")));
|
||||
|
||||
final OldJSONObject json = JSONUtil.parseObj(userA);
|
||||
final JSONObject json = JSONUtil.parseObj(userA);
|
||||
final UserA userA2 = json.toBean(UserA.class);
|
||||
// 测试数组
|
||||
Assertions.assertEquals("seq1", userA2.getSqs().get(0).getSeq());
|
||||
@@ -257,7 +257,7 @@ public class JSONObjectTest {
|
||||
@Test
|
||||
public void toBeanTest5() {
|
||||
final String readUtf8Str = ResourceUtil.readUtf8Str("suiteReport.json");
|
||||
final OldJSONObject json = JSONUtil.parseObj(readUtf8Str);
|
||||
final JSONObject json = JSONUtil.parseObj(readUtf8Str);
|
||||
final SuiteReport bean = json.toBean(SuiteReport.class);
|
||||
|
||||
// 第一层
|
||||
@@ -276,7 +276,7 @@ public class JSONObjectTest {
|
||||
*/
|
||||
@Test
|
||||
public void toBeanTest6() {
|
||||
final OldJSONObject json = JSONUtil.ofObj()
|
||||
final JSONObject json = JSONUtil.ofObj()
|
||||
.set("targetUrl", "http://test.com")
|
||||
.set("success", "true")
|
||||
.set("result", JSONUtil.ofObj()
|
||||
@@ -313,7 +313,7 @@ public class JSONObjectTest {
|
||||
userA.setDate(new Date());
|
||||
userA.setSqs(ListUtil.of(new Seq(null), new Seq("seq2")));
|
||||
|
||||
final OldJSONObject json = JSONUtil.parseObj(userA, false);
|
||||
final JSONObject json = JSONUtil.parseObj(userA, false);
|
||||
|
||||
Assertions.assertTrue(json.containsKey("a"));
|
||||
Assertions.assertTrue(json.getJSONArray("sqs").getJSONObject(0).containsKey("seq"));
|
||||
@@ -328,9 +328,9 @@ public class JSONObjectTest {
|
||||
bean.setStrValue("strTest");
|
||||
bean.setTestEnum(TestEnum.TYPE_B);
|
||||
|
||||
final OldJSONObject json = JSONUtil.parseObj(bean, false);
|
||||
final JSONObject json = JSONUtil.parseObj(bean, false);
|
||||
// 枚举转换检查,更新:枚举原样保存,在writer时调用toString。
|
||||
Assertions.assertEquals(TestEnum.TYPE_B, json.get("testEnum"));
|
||||
Assertions.assertEquals(TestEnum.TYPE_B, json.getObj("testEnum"));
|
||||
|
||||
final TestBean bean2 = json.toBean(TestBean.class);
|
||||
Assertions.assertEquals(bean.toString(), bean2.toString());
|
||||
@@ -338,7 +338,7 @@ public class JSONObjectTest {
|
||||
|
||||
@Test
|
||||
public void parseBeanTest3() {
|
||||
final OldJSONObject json = JSONUtil.ofObj()
|
||||
final JSONObject json = JSONUtil.ofObj()
|
||||
.set("code", 22)
|
||||
.set("data", "{\"jobId\": \"abc\", \"videoUrl\": \"http://a.com/a.mp4\"}");
|
||||
|
||||
@@ -355,7 +355,7 @@ public class JSONObjectTest {
|
||||
userA.setName("nameTest");
|
||||
userA.setDate(new Date());
|
||||
|
||||
final OldJSONObject userAJson = JSONUtil.parseObj(userA);
|
||||
final JSONObject userAJson = JSONUtil.parseObj(userA);
|
||||
final UserB userB = JSONUtil.toBean(userAJson, UserB.class);
|
||||
|
||||
Assertions.assertEquals(userA.getName(), userB.getName());
|
||||
@@ -369,9 +369,8 @@ public class JSONObjectTest {
|
||||
userA.setName("nameTest");
|
||||
userA.setDate(DateUtil.parse("2018-10-25"));
|
||||
|
||||
final OldJSONObject userAJson = JSONUtil.parseObj(userA);
|
||||
// 自定义日期格式
|
||||
userAJson.setDateFormat("yyyy-MM-dd");
|
||||
final JSONObject userAJson = JSONUtil.parseObj(userA, JSONConfig.of().setDateFormat("yyyy-MM-dd"));
|
||||
|
||||
final UserA bean = JSONUtil.toBean(userAJson.toString(), UserA.class);
|
||||
Assertions.assertEquals(DateUtil.parse("2018-10-25"), bean.getDate());
|
||||
@@ -379,7 +378,7 @@ public class JSONObjectTest {
|
||||
|
||||
@Test
|
||||
public void beanTransTest3() {
|
||||
final OldJSONObject userAJson = JSONUtil.ofObj()
|
||||
final JSONObject userAJson = JSONUtil.ofObj()
|
||||
.set("a", "AValue")
|
||||
.set("name", "nameValue")
|
||||
.set("date", "08:00:00");
|
||||
@@ -394,10 +393,10 @@ public class JSONObjectTest {
|
||||
userA.setName("nameTest");
|
||||
userA.setDate(new Date());
|
||||
|
||||
final OldJSONObject userAJson = JSONUtil.parseObj(userA);
|
||||
final JSONObject userAJson = JSONUtil.parseObj(userA);
|
||||
Assertions.assertFalse(userAJson.containsKey("a"));
|
||||
|
||||
final OldJSONObject userAJsonWithNullValue = JSONUtil.parseObj(userA, false);
|
||||
final JSONObject userAJsonWithNullValue = JSONUtil.parseObj(userA, false);
|
||||
Assertions.assertTrue(userAJsonWithNullValue.containsKey("a"));
|
||||
Assertions.assertTrue(userAJsonWithNullValue.containsKey("sqs"));
|
||||
}
|
||||
@@ -405,7 +404,7 @@ public class JSONObjectTest {
|
||||
@Test
|
||||
public void specialCharTest() {
|
||||
final String json = "{\"pattern\": \"[abc]\b\u2001\", \"pattern2Json\": {\"patternText\": \"[ab]\\b\"}}";
|
||||
final OldJSONObject obj = JSONUtil.parseObj(json);
|
||||
final JSONObject obj = JSONUtil.parseObj(json);
|
||||
Assertions.assertEquals("[abc]\\b\\u2001", obj.getStrEscaped("pattern"));
|
||||
Assertions.assertEquals("{\"patternText\":\"[ab]\\b\"}", obj.getStrEscaped("pattern2Json"));
|
||||
}
|
||||
@@ -413,7 +412,7 @@ public class JSONObjectTest {
|
||||
@Test
|
||||
public void getStrTest() {
|
||||
final String json = "{\"name\": \"yyb\\nbbb\"}";
|
||||
final OldJSONObject jsonObject = JSONUtil.parseObj(json);
|
||||
final JSONObject jsonObject = JSONUtil.parseObj(json);
|
||||
|
||||
// 没有转义按照默认规则显示
|
||||
Assertions.assertEquals("yyb\nbbb", jsonObject.getStr("name"));
|
||||
@@ -430,16 +429,16 @@ public class JSONObjectTest {
|
||||
beanWithAlias.setValue1("张三");
|
||||
beanWithAlias.setValue2(35);
|
||||
|
||||
final OldJSONObject jsonObject = JSONUtil.parseObj(beanWithAlias);
|
||||
final JSONObject jsonObject = JSONUtil.parseObj(beanWithAlias);
|
||||
Assertions.assertEquals("张三", jsonObject.getStr("name"));
|
||||
Assertions.assertEquals(new Integer(35), jsonObject.getInt("age"));
|
||||
Assertions.assertEquals(Integer.valueOf(35), jsonObject.getInt("age"));
|
||||
|
||||
final OldJSONObject json = JSONUtil.ofObj()
|
||||
final JSONObject json = JSONUtil.ofObj()
|
||||
.set("name", "张三")
|
||||
.set("age", 35);
|
||||
final BeanWithAlias bean = JSONUtil.toBean(Objects.requireNonNull(json).toString(), BeanWithAlias.class);
|
||||
Assertions.assertEquals("张三", bean.getValue1());
|
||||
Assertions.assertEquals(new Integer(35), bean.getValue2());
|
||||
Assertions.assertEquals(Integer.valueOf(35), bean.getValue2());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -447,7 +446,7 @@ public class JSONObjectTest {
|
||||
final JSONConfig jsonConfig = JSONConfig.of();
|
||||
jsonConfig.setDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
final OldJSONObject json = new OldJSONObject(jsonConfig);
|
||||
final JSONObject json = new JSONObject(jsonConfig);
|
||||
json.append("date", DateUtil.parse("2020-06-05 11:16:11"));
|
||||
json.append("bbb", "222");
|
||||
json.append("aaa", "123");
|
||||
@@ -460,7 +459,7 @@ public class JSONObjectTest {
|
||||
jsonConfig.setDateFormat("yyyy#MM#dd");
|
||||
|
||||
final Date date = DateUtil.parse("2020-06-05 11:16:11");
|
||||
final OldJSONObject json = new OldJSONObject(jsonConfig);
|
||||
final JSONObject json = new JSONObject(jsonConfig);
|
||||
json.set("date", date);
|
||||
json.set("bbb", "222");
|
||||
json.set("aaa", "123");
|
||||
@@ -470,7 +469,7 @@ public class JSONObjectTest {
|
||||
Assertions.assertEquals(jsonStr, json.toString());
|
||||
|
||||
// 解析测试
|
||||
final OldJSONObject parse = JSONUtil.parseObj(jsonStr, jsonConfig);
|
||||
final JSONObject parse = JSONUtil.parseObj(jsonStr, jsonConfig);
|
||||
Assertions.assertEquals(DateUtil.beginOfDay(date), parse.getDate("date"));
|
||||
}
|
||||
|
||||
@@ -480,13 +479,13 @@ public class JSONObjectTest {
|
||||
final JSONConfig jsonConfig = JSONConfig.of().setDateFormat("#sss");
|
||||
|
||||
final Date date = DateUtil.parse("2020-06-05 11:16:11");
|
||||
final OldJSONObject json = new OldJSONObject(jsonConfig);
|
||||
final JSONObject json = new JSONObject(jsonConfig);
|
||||
json.set("date", date);
|
||||
|
||||
Assertions.assertEquals("{\"date\":1591326971}", json.toString());
|
||||
|
||||
// 解析测试
|
||||
final OldJSONObject parse = JSONUtil.parseObj(json.toString(), jsonConfig);
|
||||
final JSONObject parse = JSONUtil.parseObj(json.toString(), jsonConfig);
|
||||
Assertions.assertEquals(date, DateUtil.date(parse.getDate("date")));
|
||||
}
|
||||
|
||||
@@ -496,7 +495,7 @@ public class JSONObjectTest {
|
||||
jsonConfig.setDateFormat("#sss");
|
||||
|
||||
final Date date = DateUtil.parse("2020-06-05 11:16:11");
|
||||
final OldJSONObject json = new OldJSONObject(jsonConfig);
|
||||
final JSONObject json = new JSONObject(jsonConfig);
|
||||
json.set("date", date);
|
||||
json.set("bbb", "222");
|
||||
json.set("aaa", "123");
|
||||
@@ -506,14 +505,14 @@ public class JSONObjectTest {
|
||||
Assertions.assertEquals(jsonStr, json.toString());
|
||||
|
||||
// 解析测试
|
||||
final OldJSONObject parse = JSONUtil.parseObj(jsonStr, jsonConfig);
|
||||
final JSONObject parse = JSONUtil.parseObj(jsonStr, jsonConfig);
|
||||
Assertions.assertEquals(date, parse.getDate("date"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getTimestampTest() {
|
||||
final String timeStr = "1970-01-01 00:00:00";
|
||||
final OldJSONObject jsonObject = JSONUtil.ofObj().set("time", timeStr);
|
||||
final JSONObject jsonObject = JSONUtil.ofObj().set("time", timeStr);
|
||||
final Timestamp time = jsonObject.get("time", Timestamp.class);
|
||||
Assertions.assertEquals("1970-01-01 00:00:00.0", time.toString());
|
||||
}
|
||||
@@ -559,7 +558,7 @@ public class JSONObjectTest {
|
||||
@Test
|
||||
public void parseBeanSameNameTest() {
|
||||
final SameNameBean sameNameBean = new SameNameBean();
|
||||
final OldJSONObject parse = JSONUtil.parseObj(sameNameBean);
|
||||
final JSONObject parse = JSONUtil.parseObj(sameNameBean);
|
||||
Assertions.assertEquals("123", parse.getStr("username"));
|
||||
Assertions.assertEquals("abc", parse.getStr("userName"));
|
||||
|
||||
@@ -599,7 +598,7 @@ public class JSONObjectTest {
|
||||
final Set<Map.Entry<String, String>> entries = of.entrySet();
|
||||
final Map.Entry<String, String> next = entries.iterator().next();
|
||||
|
||||
final OldJSONObject jsonObject = JSONUtil.parseObj(next);
|
||||
final JSONObject jsonObject = JSONUtil.parseObj(next);
|
||||
Assertions.assertEquals("{\"test\":\"testValue\"}", jsonObject.toString());
|
||||
}
|
||||
|
||||
@@ -607,7 +606,7 @@ public class JSONObjectTest {
|
||||
public void createJSONObjectTest() {
|
||||
Assertions.assertThrows(JSONException.class, ()->{
|
||||
// 集合类不支持转为JSONObject
|
||||
new OldJSONObject(new JSONArray(), JSONConfig.of());
|
||||
JSONUtil.parseObj(new JSONArray(), JSONConfig.of());
|
||||
});
|
||||
}
|
||||
|
||||
@@ -622,7 +621,7 @@ public class JSONObjectTest {
|
||||
|
||||
@Test
|
||||
public void appendTest() {
|
||||
final OldJSONObject jsonObject = JSONUtil.ofObj().append("key1", "value1");
|
||||
final JSONObject jsonObject = JSONUtil.ofObj().append("key1", "value1");
|
||||
Assertions.assertEquals("{\"key1\":\"value1\"}", jsonObject.toString());
|
||||
|
||||
jsonObject.append("key1", "value2");
|
||||
@@ -634,7 +633,7 @@ public class JSONObjectTest {
|
||||
|
||||
@Test
|
||||
public void putByPathTest() {
|
||||
final OldJSONObject json = new OldJSONObject();
|
||||
final JSONObject json = new JSONObject();
|
||||
json.putByPath("aa.bb", "BB");
|
||||
Assertions.assertEquals("{\"aa\":{\"bb\":\"BB\"}}", json.toString());
|
||||
}
|
||||
@@ -655,7 +654,7 @@ public class JSONObjectTest {
|
||||
|
||||
@Test
|
||||
public void filterIncludeTest() {
|
||||
final OldJSONObject json1 = JSONUtil.ofObj(JSONConfig.of())
|
||||
final JSONObject json1 = JSONUtil.ofObj(JSONConfig.of())
|
||||
.set("a", "value1")
|
||||
.set("b", "value2")
|
||||
.set("c", "value3")
|
||||
@@ -667,7 +666,7 @@ public class JSONObjectTest {
|
||||
|
||||
@Test
|
||||
public void filterExcludeTest() {
|
||||
final OldJSONObject json1 = JSONUtil.ofObj(JSONConfig.of())
|
||||
final JSONObject json1 = JSONUtil.ofObj(JSONConfig.of())
|
||||
.set("a", "value1")
|
||||
.set("b", "value2")
|
||||
.set("c", "value3")
|
||||
@@ -679,7 +678,7 @@ public class JSONObjectTest {
|
||||
|
||||
@Test
|
||||
public void editTest() {
|
||||
final OldJSONObject json1 = JSONUtil.ofObj(JSONConfig.of())
|
||||
final JSONObject json1 = JSONUtil.ofObj(JSONConfig.of())
|
||||
.set("a", "value1")
|
||||
.set("b", "value2")
|
||||
.set("c", "value3")
|
||||
@@ -699,7 +698,7 @@ public class JSONObjectTest {
|
||||
|
||||
@Test
|
||||
public void toUnderLineCaseTest() {
|
||||
final OldJSONObject json1 = JSONUtil.ofObj(JSONConfig.of())
|
||||
final JSONObject json1 = JSONUtil.ofObj(JSONConfig.of())
|
||||
.set("aKey", "value1")
|
||||
.set("bJob", "value2")
|
||||
.set("cGood", "value3")
|
||||
@@ -714,7 +713,7 @@ public class JSONObjectTest {
|
||||
|
||||
@Test
|
||||
public void nullToEmptyTest() {
|
||||
final OldJSONObject json1 = JSONUtil.ofObj(JSONConfig.of().setIgnoreNullValue(false))
|
||||
final JSONObject json1 = JSONUtil.ofObj(JSONConfig.of().setIgnoreNullValue(false))
|
||||
.set("a", null)
|
||||
.set("b", "value2");
|
||||
|
||||
@@ -729,22 +728,22 @@ public class JSONObjectTest {
|
||||
public void parseFilterTest() {
|
||||
final String jsonStr = "{\"b\":\"value2\",\"c\":\"value3\",\"a\":\"value1\", \"d\": true, \"e\": null}";
|
||||
//noinspection MismatchedQueryAndUpdateOfCollection
|
||||
final OldJSONObject jsonObject = new OldJSONObject(jsonStr, null, (pair)-> "b".equals(pair.getKey()));
|
||||
final JSONObject jsonObject = JSONUtil.parseObj(jsonStr, null, (pair)-> "b".equals(pair.getKey()));
|
||||
Assertions.assertEquals(1, jsonObject.size());
|
||||
Assertions.assertEquals("value2", jsonObject.get("b"));
|
||||
Assertions.assertEquals("value2", jsonObject.getObj("b"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseFilterEditTest() {
|
||||
final String jsonStr = "{\"b\":\"value2\",\"c\":\"value3\",\"a\":\"value1\", \"d\": true, \"e\": null}";
|
||||
//noinspection MismatchedQueryAndUpdateOfCollection
|
||||
final OldJSONObject jsonObject = new OldJSONObject(jsonStr, null, (pair)-> {
|
||||
final JSONObject jsonObject = JSONUtil.parseObj(jsonStr, null, (pair)-> {
|
||||
if("b".equals(pair.getKey())){
|
||||
final JSONPrimitive primitive = (JSONPrimitive) pair.getValue();
|
||||
pair.setValue(primitive.getValue() + "_edit");
|
||||
}
|
||||
return true;
|
||||
});
|
||||
Assertions.assertEquals("value2_edit", jsonObject.get("b"));
|
||||
Assertions.assertEquals("value2_edit", jsonObject.getObj("b"));
|
||||
}
|
||||
}
|
||||
|
@@ -27,7 +27,7 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
public class JSONTokenerTest {
|
||||
@Test
|
||||
void parseTest() {
|
||||
final OldJSONObject jsonObject = JSONUtil.parseObj(ResourceUtil.getUtf8Reader("issue1200.json"));
|
||||
final JSONObject jsonObject = JSONUtil.parseObj(ResourceUtil.getUtf8Reader("issue1200.json"));
|
||||
assertNotNull(jsonObject);
|
||||
}
|
||||
|
||||
|
@@ -124,7 +124,7 @@ public class JSONUtilTest {
|
||||
@Test
|
||||
public void parseNumberToJSONObjectTest() {
|
||||
assertThrows(JSONException.class, () -> {
|
||||
final OldJSONObject json = JSONUtil.parseObj(123L);
|
||||
final JSONObject json = JSONUtil.parseObj(123L);
|
||||
Assertions.assertNotNull(json);
|
||||
});
|
||||
}
|
||||
@@ -134,8 +134,8 @@ public class JSONUtilTest {
|
||||
*/
|
||||
@Test
|
||||
public void parseNumberToJSONObjectTest2() {
|
||||
final OldJSONObject json = JSONUtil.parseObj(123L, JSONConfig.of().setIgnoreError(true));
|
||||
assertEquals(new OldJSONObject(), json);
|
||||
final JSONObject json = JSONUtil.parseObj(123L, JSONConfig.of().setIgnoreError(true));
|
||||
assertEquals(new JSONObject(), json);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -169,7 +169,7 @@ public class JSONUtilTest {
|
||||
data.put("model", model);
|
||||
data.put("model2", model);
|
||||
|
||||
final OldJSONObject jsonObject = JSONUtil.parseObj(data);
|
||||
final JSONObject jsonObject = JSONUtil.parseObj(data);
|
||||
|
||||
Assertions.assertTrue(jsonObject.containsKey("model"));
|
||||
assertEquals(1, jsonObject.getJSONObject("model").getInt("type").intValue());
|
||||
@@ -180,7 +180,7 @@ public class JSONUtilTest {
|
||||
@Test
|
||||
public void toJsonStrTest3() {
|
||||
// 验证某个字段为JSON字符串时转义是否规范
|
||||
final OldJSONObject object = new OldJSONObject(JSONConfig.of().setIgnoreError(true));
|
||||
final JSONObject object = new JSONObject(JSONConfig.of().setIgnoreError(true));
|
||||
object.set("name", "123123");
|
||||
object.set("value", "\\");
|
||||
object.set("value2", "</");
|
||||
@@ -188,12 +188,12 @@ public class JSONUtilTest {
|
||||
final HashMap<String, String> map = MapUtil.newHashMap();
|
||||
map.put("user", object.toString());
|
||||
|
||||
final OldJSONObject json = JSONUtil.parseObj(map);
|
||||
assertEquals("{\"name\":\"123123\",\"value\":\"\\\\\",\"value2\":\"</\"}", json.get("user"));
|
||||
final JSONObject json = JSONUtil.parseObj(map);
|
||||
assertEquals("{\"name\":\"123123\",\"value\":\"\\\\\",\"value2\":\"</\"}", json.getObj("user"));
|
||||
assertEquals("{\"user\":\"{\\\"name\\\":\\\"123123\\\",\\\"value\\\":\\\"\\\\\\\\\\\",\\\"value2\\\":\\\"</\\\"}\"}", json.toString());
|
||||
|
||||
final OldJSONObject json2 = JSONUtil.parseObj(json.toString());
|
||||
assertEquals("{\"name\":\"123123\",\"value\":\"\\\\\",\"value2\":\"</\"}", json2.get("user"));
|
||||
final JSONObject json2 = JSONUtil.parseObj(json.toString());
|
||||
assertEquals("{\"name\":\"123123\",\"value\":\"\\\\\",\"value2\":\"</\"}", json2.getObj("user"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -230,7 +230,7 @@ public class JSONUtilTest {
|
||||
final UserC user = JSONUtil.toBean(json, UserC.class);
|
||||
Assertions.assertNotNull(user.getProp());
|
||||
final String prop = user.getProp();
|
||||
final OldJSONObject propJson = JSONUtil.parseObj(prop);
|
||||
final JSONObject propJson = JSONUtil.parseObj(prop);
|
||||
assertEquals("男", propJson.getStr("gender"));
|
||||
assertEquals(18, propJson.getInt("age").intValue());
|
||||
// Assertions.assertEquals("{\"age\":18,\"gender\":\"男\"}", user.getProp());
|
||||
@@ -239,31 +239,31 @@ public class JSONUtilTest {
|
||||
@Test
|
||||
public void getStrTest() {
|
||||
final String html = "{\"name\":\"Something must have been changed since you leave\"}";
|
||||
final OldJSONObject jsonObject = JSONUtil.parseObj(html);
|
||||
final JSONObject jsonObject = JSONUtil.parseObj(html);
|
||||
assertEquals("Something must have been changed since you leave", jsonObject.getStr("name"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getStrTest2() {
|
||||
final String html = "{\"name\":\"Something\\u00a0must have been changed since you leave\"}";
|
||||
final OldJSONObject jsonObject = JSONUtil.parseObj(html);
|
||||
final JSONObject jsonObject = JSONUtil.parseObj(html);
|
||||
assertEquals("Something\\u00a0must\\u00a0have\\u00a0been\\u00a0changed\\u00a0since\\u00a0you\\u00a0leave", jsonObject.getStrEscaped("name"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseFromXmlTest() {
|
||||
final String s = "<sfzh>640102197312070614</sfzh><sfz>640102197312070614X</sfz><name>aa</name><gender>1</gender>";
|
||||
final OldJSONObject json = JSONUtil.parseFromXml(s);
|
||||
assertEquals(640102197312070614L, json.get("sfzh"));
|
||||
assertEquals("640102197312070614X", json.get("sfz"));
|
||||
assertEquals("aa", json.get("name"));
|
||||
assertEquals(1, json.get("gender"));
|
||||
final JSONObject json = JSONUtil.parseFromXml(s);
|
||||
assertEquals(640102197312070614L, json.getObj("sfzh"));
|
||||
assertEquals("640102197312070614X", json.getObj("sfz"));
|
||||
assertEquals("aa", json.getObj("name"));
|
||||
assertEquals(1, json.getObj("gender"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void doubleTest() {
|
||||
final String json = "{\"test\": 12.00}";
|
||||
final OldJSONObject jsonObject = JSONUtil.parseObj(json);
|
||||
final JSONObject jsonObject = JSONUtil.parseObj(json);
|
||||
//noinspection BigDecimalMethodWithoutRoundingCalled
|
||||
assertEquals("12.00", jsonObject.getBigDecimal("test").setScale(2).toString());
|
||||
}
|
||||
@@ -271,12 +271,12 @@ public class JSONUtilTest {
|
||||
@Test
|
||||
public void setStripTrailingZerosTest() {
|
||||
// 默认去除多余的0
|
||||
final OldJSONObject jsonObjectDefault = JSONUtil.ofObj()
|
||||
final JSONObject jsonObjectDefault = JSONUtil.ofObj()
|
||||
.set("test2", 12.00D);
|
||||
assertEquals("{\"test2\":12}", jsonObjectDefault.toString());
|
||||
|
||||
// 不去除多余的0
|
||||
final OldJSONObject jsonObject = JSONUtil.ofObj(JSONConfig.of().setStripTrailingZeros(false))
|
||||
final JSONObject jsonObject = JSONUtil.ofObj(JSONConfig.of().setStripTrailingZeros(false))
|
||||
.set("test2", 12.00D);
|
||||
assertEquals("{\"test2\":12.0}", jsonObject.toString());
|
||||
|
||||
@@ -288,7 +288,7 @@ public class JSONUtilTest {
|
||||
@Test
|
||||
public void parseObjTest() {
|
||||
// 测试转义
|
||||
final OldJSONObject jsonObject = JSONUtil.parseObj("{\n" +
|
||||
final JSONObject jsonObject = JSONUtil.parseObj("{\n" +
|
||||
" \"test\": \"\\\\地库地库\",\n" +
|
||||
"}");
|
||||
|
||||
@@ -299,7 +299,7 @@ public class JSONUtilTest {
|
||||
public void sqlExceptionTest() {
|
||||
//https://github.com/dromara/hutool/issues/1399
|
||||
// SQLException实现了Iterable接口,默认是遍历之,会栈溢出,修正后只返回string
|
||||
final OldJSONObject set = JSONUtil.ofObj().set("test", new SQLException("test"));
|
||||
final JSONObject set = JSONUtil.ofObj().set("test", new SQLException("test"));
|
||||
assertEquals("{\"test\":\"java.sql.SQLException: test\"}", set.toString());
|
||||
}
|
||||
|
||||
@@ -312,7 +312,7 @@ public class JSONUtilTest {
|
||||
|
||||
@Test
|
||||
public void toXmlTest() {
|
||||
final OldJSONObject obj = JSONUtil.ofObj();
|
||||
final JSONObject obj = JSONUtil.ofObj();
|
||||
obj.set("key1", "v1")
|
||||
.set("key2", ListUtil.view("a", "b", "c"));
|
||||
final String xmlStr = JSONUtil.toXmlStr(obj);
|
||||
|
@@ -26,7 +26,7 @@ public class JSONWriterTest {
|
||||
|
||||
@Test
|
||||
public void writeDateTest() {
|
||||
final OldJSONObject jsonObject = JSONUtil.ofObj(JSONConfig.of().setDateFormat("yyyy-MM-dd"))
|
||||
final JSONObject jsonObject = JSONUtil.ofObj(JSONConfig.of().setDateFormat("yyyy-MM-dd"))
|
||||
.set("date", DateUtil.parse("2022-09-30"));
|
||||
|
||||
// 日期原样写入
|
||||
@@ -37,7 +37,7 @@ public class JSONWriterTest {
|
||||
Assertions.assertEquals("{\"date\":\"2022-09-30\"}", jsonObject.toString());
|
||||
|
||||
// 自定义日期格式解析生效
|
||||
final OldJSONObject parse = JSONUtil.parseObj(jsonObject.toString(), JSONConfig.of().setDateFormat("yyyy-MM-dd"));
|
||||
Assertions.assertEquals(String.class, parse.get("date").getClass());
|
||||
final JSONObject parse = JSONUtil.parseObj(jsonObject.toString(), JSONConfig.of().setDateFormat("yyyy-MM-dd"));
|
||||
Assertions.assertEquals(String.class, parse.getObj("date").getClass());
|
||||
}
|
||||
}
|
||||
|
@@ -47,7 +47,7 @@ public class ParseBeanTest {
|
||||
final A a = new A();
|
||||
a.setBs(ListUtil.of(b1, b2));
|
||||
|
||||
final OldJSONObject json = JSONUtil.parseObj(a);
|
||||
final JSONObject json = JSONUtil.parseObj(a);
|
||||
final A a1 = JSONUtil.toBean(json, A.class);
|
||||
Assertions.assertEquals(json.toString(), JSONUtil.toJsonStr(a1));
|
||||
}
|
||||
|
@@ -28,7 +28,7 @@ public class Pr3067Test {
|
||||
|
||||
@Test
|
||||
public void getListByPathTest1() {
|
||||
final OldJSONObject json = JSONUtil.parseObj(ResourceUtil.readUtf8Str("test_json_path_001.json"));
|
||||
final JSONObject json = JSONUtil.parseObj(ResourceUtil.readUtf8Str("test_json_path_001.json"));
|
||||
final List<TestUser> resultList = json.getByPath("testUserList[1].testArray",
|
||||
new TypeReference<List<TestUser>>() {});
|
||||
|
||||
|
@@ -22,7 +22,7 @@ import org.junit.jupiter.api.Test;
|
||||
public class Pr3507Test {
|
||||
@Test
|
||||
void writeClassTest() {
|
||||
final OldJSONObject set = JSONUtil.ofObj().set("name", Pr3507Test.class);
|
||||
final JSONObject set = JSONUtil.ofObj().set("name", Pr3507Test.class);
|
||||
Assertions.assertEquals("{\"name\":\"org.dromara.hutool.json.Pr3507Test\"}", set.toString());
|
||||
}
|
||||
}
|
||||
|
@@ -35,7 +35,7 @@ public class TransientTest {
|
||||
detailBill.setBizNo("bizNo");
|
||||
|
||||
//noinspection MismatchedQueryAndUpdateOfCollection
|
||||
final OldJSONObject jsonObject = new OldJSONObject(detailBill,
|
||||
final JSONObject jsonObject = JSONUtil.parseObj(detailBill,
|
||||
JSONConfig.of().setTransientSupport(false));
|
||||
Assertions.assertEquals("{\"id\":\"3243\",\"bizNo\":\"bizNo\"}", jsonObject.toString());
|
||||
}
|
||||
@@ -47,7 +47,7 @@ public class TransientTest {
|
||||
detailBill.setBizNo("bizNo");
|
||||
|
||||
//noinspection MismatchedQueryAndUpdateOfCollection
|
||||
final OldJSONObject jsonObject = new OldJSONObject(detailBill,
|
||||
final JSONObject jsonObject = JSONUtil.parseObj(detailBill,
|
||||
JSONConfig.of().setTransientSupport(true));
|
||||
Assertions.assertEquals("{\"bizNo\":\"bizNo\"}", jsonObject.toString());
|
||||
}
|
||||
@@ -58,7 +58,7 @@ public class TransientTest {
|
||||
detailBill.setId("3243");
|
||||
detailBill.setBizNo("bizNo");
|
||||
|
||||
final OldJSONObject jsonObject = new OldJSONObject(detailBill,
|
||||
final JSONObject jsonObject = JSONUtil.parseObj(detailBill,
|
||||
JSONConfig.of().setTransientSupport(false));
|
||||
|
||||
final Bill bill = jsonObject.toBean(Bill.class);
|
||||
@@ -72,7 +72,7 @@ public class TransientTest {
|
||||
detailBill.setId("3243");
|
||||
detailBill.setBizNo("bizNo");
|
||||
|
||||
final OldJSONObject jsonObject = new OldJSONObject(detailBill,
|
||||
final JSONObject jsonObject = JSONUtil.parseObj(detailBill,
|
||||
JSONConfig.of().setTransientSupport(true));
|
||||
|
||||
final Bill bill = jsonObject.toBean(Bill.class);
|
||||
|
@@ -16,11 +16,11 @@
|
||||
|
||||
package org.dromara.hutool.json.jwt;
|
||||
|
||||
import lombok.Data;
|
||||
import org.dromara.hutool.core.date.DateUtil;
|
||||
import org.dromara.hutool.core.date.TimeUtil;
|
||||
import org.dromara.hutool.json.OldJSONObject;
|
||||
import org.dromara.hutool.json.JSONObject;
|
||||
import org.dromara.hutool.json.JSONUtil;
|
||||
import lombok.Data;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@@ -40,7 +40,7 @@ public class IssueI6IS5BTest {
|
||||
jwtToken.setIat(iat);
|
||||
final String token = JWTUtil.createToken(JSONUtil.parseObj(jwtToken), "123".getBytes(StandardCharsets.UTF_8));
|
||||
Assertions.assertEquals("eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE2Nzc3NzI4MDB9.SXU_mm1wT5lNoK-Dq5Y8f3BItv_44zuAlyeWLqajpXg", token);
|
||||
final OldJSONObject payloads = JWTUtil.parseToken(token).getPayloads();
|
||||
final JSONObject payloads = JWTUtil.parseToken(token).getPayloads();
|
||||
Assertions.assertEquals("{\"iat\":1677772800}", payloads.toString());
|
||||
final JwtToken o = payloads.toBean(JwtToken.class);
|
||||
Assertions.assertEquals(iat, o.getIat());
|
||||
@@ -58,7 +58,7 @@ public class IssueI6IS5BTest {
|
||||
jwtToken.setIat(iat);
|
||||
final String token = JWTUtil.createToken(JSONUtil.parseObj(jwtToken), "123".getBytes(StandardCharsets.UTF_8));
|
||||
Assertions.assertEquals("eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE2Nzc3NzI4MDB9.SXU_mm1wT5lNoK-Dq5Y8f3BItv_44zuAlyeWLqajpXg", token);
|
||||
final OldJSONObject payloads = JWTUtil.parseToken(token).getPayloads();
|
||||
final JSONObject payloads = JWTUtil.parseToken(token).getPayloads();
|
||||
Assertions.assertEquals("{\"iat\":1677772800}", payloads.toString());
|
||||
final JwtToken2 o = payloads.toBean(JwtToken2.class);
|
||||
Assertions.assertEquals(iat, o.getIat());
|
||||
|
@@ -16,7 +16,7 @@
|
||||
|
||||
package org.dromara.hutool.json.jwt;
|
||||
|
||||
import org.dromara.hutool.json.OldJSONObject;
|
||||
import org.dromara.hutool.json.JSONObject;
|
||||
import org.dromara.hutool.json.JSONUtil;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -28,7 +28,7 @@ public class IssueI76TRQTest {
|
||||
@Test
|
||||
void createTokenTest() {
|
||||
final String str = "{\"editorConfig\":{\"mode\":\"edit\",\"callbackUrl\":\"http://172.16.30.53:8080/OnlineEditorsExampleJava/IndexServlet?type\\u003dtrack\\u0026fileName\\u003dnew.docx\\u0026userAddress\\u003d172.16.30.53\",\"lang\":\"zh\",\"createUrl\":\"http://172.16.30.53:8080/OnlineEditorsExampleJava/EditorServlet?fileExt\\u003ddocx\",\"templates\":[{\"image\":\"\",\"title\":\"Blank\",\"url\":\"http://172.16.30.53:8080/OnlineEditorsExampleJava/EditorServlet?fileExt\\u003ddocx\"},{\"image\":\"http://172.16.30.53:8080/OnlineEditorsExampleJava/css/img/file_docx.svg\",\"title\":\"With sample content\",\"url\":\"http://172.16.30.53:8080/OnlineEditorsExampleJava/EditorServlet?fileExt\\u003ddocx\\u0026sample\\u003dtrue\"}],\"user\":{\"id\":\"uid-1\",\"name\":\"John Smith\",\"group\":\"\"},\"customization\":{\"goback\":{\"url\":\"http://172.16.30.53:8080/OnlineEditorsExampleJava/IndexServlet\"},\"forcesave\":false,\"submitForm\":false,\"about\":true,\"comments\":true,\"feedback\":true}},\"documentType\":\"word\",\"document\":{\"title\":\"new.docx\",\"url\":\"http://172.16.30.53:8080/OnlineEditorsExampleJava/IndexServlet?type\\u003ddownload\\u0026fileName\\u003dnew.docx\\u0026userAddress\\u003d172.16.30.53\",\"directUrl\":\"\",\"fileType\":\"docx\",\"key\":\"1956415572\",\"info\":{\"owner\":\"Me\",\"uploaded\":\"Fri May 19 2023\"},\"permissions\":{\"comment\":true,\"copy\":true,\"download\":true,\"edit\":true,\"print\":true,\"fillForms\":true,\"modifyFilter\":true,\"modifyContentControl\":true,\"review\":true,\"chat\":true,\"commentGroups\":{}}},\"type\":\"desktop\"}";
|
||||
final OldJSONObject payload = JSONUtil.parseObj(str);
|
||||
final JSONObject payload = JSONUtil.parseObj(str);
|
||||
final String token = JWTUtil.createToken(payload, "123456".getBytes());
|
||||
Assertions.assertNotNull(token);
|
||||
|
||||
|
@@ -18,7 +18,7 @@ package org.dromara.hutool.json.reader;
|
||||
|
||||
import org.dromara.hutool.json.JSON;
|
||||
import org.dromara.hutool.json.JSONConfig;
|
||||
import org.dromara.hutool.json.OldJSONObject;
|
||||
import org.dromara.hutool.json.JSONObject;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@@ -34,6 +34,6 @@ public class JSONParserTest {
|
||||
@Test
|
||||
void nextToTest() {
|
||||
final String jsonStr = "{\"a\": 1}";
|
||||
JSONParser.of(new JSONTokener(jsonStr), JSONConfig.of()).parseTo(new OldJSONObject());
|
||||
JSONParser.of(new JSONTokener(jsonStr), JSONConfig.of()).parseTo(new JSONObject());
|
||||
}
|
||||
}
|
||||
|
@@ -16,11 +16,11 @@
|
||||
|
||||
package org.dromara.hutool.json.test.bean;
|
||||
|
||||
import org.dromara.hutool.json.OldJSONObject;
|
||||
import lombok.Data;
|
||||
import org.dromara.hutool.json.JSONObject;
|
||||
|
||||
@Data
|
||||
public class JSONBean {
|
||||
private int code;
|
||||
private OldJSONObject data;
|
||||
private JSONObject data;
|
||||
}
|
||||
|
@@ -16,7 +16,7 @@
|
||||
|
||||
package org.dromara.hutool.json.xml;
|
||||
|
||||
import org.dromara.hutool.json.OldJSONObject;
|
||||
import org.dromara.hutool.json.JSONObject;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@@ -24,7 +24,7 @@ public class Issue3560Test {
|
||||
@Test
|
||||
public void toJSONObjectTest() {
|
||||
final String inPara= "<ROOT><ID>002317479934367853</ID><CONTENT><![CDATA[asdfadf&21sdgzxv&aasfasf]]></CONTENT></ROOT>";
|
||||
final OldJSONObject json = JSONXMLUtil.toJSONObject(inPara, ParseConfig.of().setKeepStrings(true));
|
||||
final JSONObject json = JSONXMLUtil.toJSONObject(inPara, ParseConfig.of().setKeepStrings(true));
|
||||
Assertions.assertEquals("{\"ROOT\":{\"ID\":\"002317479934367853\",\"CONTENT\":\"asdfadf&21sdgzxv&aasfasf\"}}", json.toString());
|
||||
}
|
||||
}
|
||||
|
@@ -16,7 +16,7 @@
|
||||
|
||||
package org.dromara.hutool.json.xml;
|
||||
|
||||
import org.dromara.hutool.json.OldJSONObject;
|
||||
import org.dromara.hutool.json.JSONObject;
|
||||
import org.dromara.hutool.json.JSONUtil;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -25,7 +25,7 @@ public class XMLTest {
|
||||
|
||||
@Test
|
||||
public void toXmlTest(){
|
||||
final OldJSONObject put = JSONUtil.ofObj()
|
||||
final JSONObject put = JSONUtil.ofObj()
|
||||
.set("aaa", "你好")
|
||||
.set("键2", "test");
|
||||
final String s = JSONUtil.toXmlStr(put);
|
||||
@@ -35,7 +35,7 @@ public class XMLTest {
|
||||
@Test
|
||||
public void escapeTest(){
|
||||
final String xml = "<a>•</a>";
|
||||
final OldJSONObject jsonObject = JSONXMLUtil.toJSONObject(xml);
|
||||
final JSONObject jsonObject = JSONXMLUtil.toJSONObject(xml);
|
||||
|
||||
Assertions.assertEquals("{\"a\":\"•\"}", jsonObject.toString());
|
||||
|
||||
@@ -45,7 +45,7 @@ public class XMLTest {
|
||||
|
||||
@Test
|
||||
public void xmlContentTest(){
|
||||
final OldJSONObject jsonObject = JSONUtil.ofObj().set("content","123456");
|
||||
final JSONObject jsonObject = JSONUtil.ofObj().set("content","123456");
|
||||
|
||||
String xml = JSONXMLUtil.toXml(jsonObject);
|
||||
Assertions.assertEquals("123456", xml);
|
||||
|
Reference in New Issue
Block a user