add JSONParser

This commit is contained in:
Looly
2024-09-13 00:55:35 +08:00
parent 7debdcef60
commit 1f705e0e1f
16 changed files with 219 additions and 109 deletions

View File

@@ -27,7 +27,7 @@ public class IssueI9DX5HTest {
void xmlToJSONTest() {
final String xml = "<GoodMsg>你好</GoodMsg>";
final JSONObject jsonObject = new JSONObject(xml, JSONConfig.of(), entry -> {
entry.setKey(StrUtil.toUnderlineCase(entry.getKey()));
entry.setKey(StrUtil.toUnderlineCase((CharSequence) entry.getKey()));
return true;
});

View File

@@ -29,10 +29,7 @@ import org.dromara.hutool.json.test.bean.KeyBean;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -322,7 +319,7 @@ public class JSONArrayTest {
if ("111".equals(o.getStr("id"))) {
o.set("name", "test1_edit");
}
mutable.set(o);
mutable.set(new AbstractMap.SimpleEntry<>(1, o));
return true;
});
assertEquals(2, array.size());

View File

@@ -0,0 +1,39 @@
/*
* Copyright (c) 2024 Hutool Team and hutool.cn
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.dromara.hutool.json.reader;
import org.dromara.hutool.json.JSON;
import org.dromara.hutool.json.JSONConfig;
import org.dromara.hutool.json.JSONObject;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class JSONParserTest {
@Test
void parseTest() {
final String jsonStr = " {\"a\": 1} ";
final JSONParser jsonParser = JSONParser.of(new JSONTokener(jsonStr), JSONConfig.of());
final JSON parse = jsonParser.parse();
Assertions.assertEquals("{\"a\":1}", parse.toString());
}
@Test
void nextToTest() {
final String jsonStr = "{\"a\": 1}";
JSONParser.of(new JSONTokener(jsonStr), JSONConfig.of()).parseTo(new JSONObject());
}
}