mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
add JSONParser
This commit is contained in:
@@ -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;
|
||||
});
|
||||
|
||||
|
@@ -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());
|
||||
|
@@ -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());
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user