add methods

This commit is contained in:
Looly
2021-10-15 01:27:16 +08:00
parent 05141a7927
commit 5cd7e806e1
5 changed files with 132 additions and 3 deletions

View File

@@ -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);
}
}

View File

@@ -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);
}
}