-
Notifications
You must be signed in to change notification settings - Fork 496
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bug fix for multi ValueFilter, for issue #1078
- Loading branch information
Showing
2 changed files
with
56 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
core/src/test/java/com/alibaba/fastjson2/issues_1000/Issue1078.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package com.alibaba.fastjson2.issues_1000; | ||
|
||
import com.alibaba.fastjson2.JSON; | ||
import com.alibaba.fastjson2.JSONWriter; | ||
import com.alibaba.fastjson2.filter.ValueFilter; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
public class Issue1078 { | ||
@Test | ||
public void test() { | ||
Map<String, String> map = new HashMap<>(); | ||
map.put("a", "b"); | ||
|
||
assertEquals( | ||
"{\"a\":\"b12\"}", | ||
JSON.toJSONString( | ||
map, | ||
new ValueFilter[]{new TestValueFilter1(), new TestValueFilter2()}, | ||
JSONWriter.Feature.WriteMapNullValue | ||
) | ||
); | ||
|
||
assertEquals( | ||
"{\"a\":\"b21\"}", | ||
JSON.toJSONString( | ||
map, | ||
new ValueFilter[]{new TestValueFilter2(), new TestValueFilter1()}, | ||
JSONWriter.Feature.WriteMapNullValue | ||
) | ||
); | ||
} | ||
|
||
public static class TestValueFilter1 implements ValueFilter { | ||
@Override | ||
public Object apply(Object o, String s, Object o1) { | ||
return o1.toString() + "1"; | ||
} | ||
} | ||
|
||
public static class TestValueFilter2 implements ValueFilter { | ||
@Override | ||
public Object apply(Object o, String s, Object o1) { | ||
return o1.toString() + "2"; | ||
} | ||
} | ||
} |