mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
add methods
This commit is contained in:
@@ -239,4 +239,28 @@ public class JSONArrayTest {
|
||||
private Integer id;
|
||||
private String name;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void filterIncludeTest(){
|
||||
JSONArray json1 = JSONUtil.createArray()
|
||||
.set("value1")
|
||||
.set("value2")
|
||||
.set("value3")
|
||||
.set(true);
|
||||
|
||||
final String s = json1.toJSONString(0, (pair) -> pair.getValue().equals("value2"));
|
||||
Assert.assertEquals("[\"value2\"]", s);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void filterExcludeTest(){
|
||||
JSONArray json1 = JSONUtil.createArray()
|
||||
.set("value1")
|
||||
.set("value2")
|
||||
.set("value3")
|
||||
.set(true);
|
||||
|
||||
final String s = json1.toJSONString(0, (pair) -> false == pair.getValue().equals("value2"));
|
||||
Assert.assertEquals("[\"value1\",\"value3\",true]", s);
|
||||
}
|
||||
}
|
||||
|
@@ -609,4 +609,28 @@ public class JSONObjectTest {
|
||||
class BigDecimalBean{
|
||||
private BigDecimal orderId;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void filterIncludeTest(){
|
||||
JSONObject json1 = JSONUtil.createObj(JSONConfig.create().setOrder(true))
|
||||
.set("a", "value1")
|
||||
.set("b", "value2")
|
||||
.set("c", "value3")
|
||||
.set("d", true);
|
||||
|
||||
final String s = json1.toJSONString(0, (pair) -> pair.getKey().equals("b"));
|
||||
Assert.assertEquals("{\"b\":\"value2\"}", s);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void filterExcludeTest(){
|
||||
JSONObject json1 = JSONUtil.createObj(JSONConfig.create().setOrder(true))
|
||||
.set("a", "value1")
|
||||
.set("b", "value2")
|
||||
.set("c", "value3")
|
||||
.set("d", true);
|
||||
|
||||
final String s = json1.toJSONString(0, (pair) -> false == pair.getKey().equals("b"));
|
||||
Assert.assertEquals("{\"a\":\"value1\",\"c\":\"value3\",\"d\":true}", s);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user