mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix bug
This commit is contained in:
26
hutool-json/src/test/java/cn/hutool/json/IssueI5OMSCTest.java
Executable file
26
hutool-json/src/test/java/cn/hutool/json/IssueI5OMSCTest.java
Executable file
@@ -0,0 +1,26 @@
|
||||
package cn.hutool.json;
|
||||
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import cn.hutool.core.io.resource.ResourceUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Predicate多层过滤
|
||||
*/
|
||||
public class IssueI5OMSCTest {
|
||||
|
||||
@Test
|
||||
public void filterTest(){
|
||||
final JSONObject json = JSONUtil.parseObj(ResourceUtil.readUtf8Str("issueI5OMSC.json"));
|
||||
|
||||
final String s = json.toJSONString(0, (entry) -> {
|
||||
final Object key = entry.getKey();
|
||||
if(key instanceof String){
|
||||
return ListUtil.of("store", "bicycle", "color", "book", "author").contains(key);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
Assert.assertEquals("{\"store\":{\"bicycle\":{\"color\":\"red\"},\"book\":[{\"author\":\"Evelyn Waugh\"},{\"author\":\"Evelyn Waugh02\"}]}}", s);
|
||||
}
|
||||
}
|
@@ -698,7 +698,7 @@ public class JSONObjectTest {
|
||||
.set("d", true);
|
||||
|
||||
final String s = json1.toJSONString(0, (pair) -> {
|
||||
pair.setKey(StrUtil.toUnderlineCase(pair.getKey()));
|
||||
pair.setKey(StrUtil.toUnderlineCase(pair.getKey().toString()));
|
||||
return true;
|
||||
});
|
||||
Assert.assertEquals("{\"a_key\":\"value1\",\"b_job\":\"value2\",\"c_good\":\"value3\",\"d\":true}", s);
|
||||
|
32
hutool-json/src/test/resources/issueI5OMSC.json
Executable file
32
hutool-json/src/test/resources/issueI5OMSC.json
Executable file
@@ -0,0 +1,32 @@
|
||||
{
|
||||
"store": {
|
||||
"bicycle": {
|
||||
"color": "red",
|
||||
"price": 19.95
|
||||
},
|
||||
"book": [
|
||||
{
|
||||
"category": "fiction",
|
||||
"author": "Evelyn Waugh",
|
||||
"title": "Sword of Honour",
|
||||
"price": 12.99,
|
||||
"items": [
|
||||
{
|
||||
"name": "wujing001",
|
||||
"age": 18
|
||||
},
|
||||
{
|
||||
"name": "wujing002",
|
||||
"age": 18
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"category": "fiction02",
|
||||
"author": "Evelyn Waugh02",
|
||||
"title": "Sword of Honour02",
|
||||
"price": 12.99
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user