mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
修改JSON的过滤接口,实现多层过滤
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);
|
||||
}
|
||||
}
|
@@ -700,7 +700,7 @@ public class JSONObjectTest {
|
||||
.set("d", true);
|
||||
|
||||
final String s = json1.toJSONString(0, (pair) -> {
|
||||
pair.setKey(StrUtil.toUnderlineCase(pair.getKey()));
|
||||
pair.setKey(StrUtil.toUnderlineCase((String)pair.getKey()));
|
||||
return true;
|
||||
});
|
||||
Assert.assertEquals("{\"a_key\":\"value1\",\"b_job\":\"value2\",\"c_good\":\"value3\",\"d\":true}", s);
|
||||
|
@@ -116,6 +116,96 @@ public class JWTSignerTest {
|
||||
signAndVerify(signer);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hmd5Test(){
|
||||
final String id = "hmd5";
|
||||
final JWTSigner signer = JWTSignerUtil.createSigner(id, KeyUtil.generateKey(AlgorithmUtil.getAlgorithm(id)));
|
||||
Assert.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm());
|
||||
|
||||
signAndVerify(signer);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hsha1Test(){
|
||||
final String id = "hsha1";
|
||||
final JWTSigner signer = JWTSignerUtil.createSigner(id, KeyUtil.generateKey(AlgorithmUtil.getAlgorithm(id)));
|
||||
Assert.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm());
|
||||
|
||||
signAndVerify(signer);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sm4cmacTest(){
|
||||
final String id = "sm4cmac";
|
||||
final JWTSigner signer = JWTSignerUtil.createSigner(id, KeyUtil.generateKey(AlgorithmUtil.getAlgorithm(id)));
|
||||
Assert.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm());
|
||||
|
||||
signAndVerify(signer);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rmd2Test(){
|
||||
final String id = "rmd2";
|
||||
final JWTSigner signer = JWTSignerUtil.createSigner(id, KeyUtil.generateKeyPair(AlgorithmUtil.getAlgorithm(id)));
|
||||
Assert.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm());
|
||||
|
||||
signAndVerify(signer);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rmd5Test(){
|
||||
final String id = "rmd5";
|
||||
final JWTSigner signer = JWTSignerUtil.createSigner(id, KeyUtil.generateKeyPair(AlgorithmUtil.getAlgorithm(id)));
|
||||
Assert.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm());
|
||||
|
||||
signAndVerify(signer);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rsha1Test(){
|
||||
final String id = "rsha1";
|
||||
final JWTSigner signer = JWTSignerUtil.createSigner(id, KeyUtil.generateKeyPair(AlgorithmUtil.getAlgorithm(id)));
|
||||
Assert.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm());
|
||||
|
||||
signAndVerify(signer);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void dnoneTest(){
|
||||
final String id = "dnone";
|
||||
final JWTSigner signer = JWTSignerUtil.createSigner(id, KeyUtil.generateKeyPair(AlgorithmUtil.getAlgorithm(id)));
|
||||
Assert.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm());
|
||||
|
||||
signAndVerify(signer);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void dsha1Test(){
|
||||
final String id = "dsha1";
|
||||
final JWTSigner signer = JWTSignerUtil.createSigner(id, KeyUtil.generateKeyPair(AlgorithmUtil.getAlgorithm(id)));
|
||||
Assert.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm());
|
||||
|
||||
signAndVerify(signer);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void enoneTest(){
|
||||
final String id = "enone";
|
||||
final JWTSigner signer = JWTSignerUtil.createSigner(id, KeyUtil.generateKeyPair(AlgorithmUtil.getAlgorithm(id)));
|
||||
Assert.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm());
|
||||
|
||||
signAndVerify(signer);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void esha1Test(){
|
||||
final String id = "esha1";
|
||||
final JWTSigner signer = JWTSignerUtil.createSigner(id, KeyUtil.generateKeyPair(AlgorithmUtil.getAlgorithm(id)));
|
||||
Assert.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm());
|
||||
|
||||
signAndVerify(signer);
|
||||
}
|
||||
|
||||
private static void signAndVerify(final JWTSigner signer){
|
||||
final JWT jwt = JWT.of()
|
||||
.setPayload("sub", "1234567890")
|
||||
|
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