Skip to content

Commit

Permalink
add testcase
Browse files Browse the repository at this point in the history
  • Loading branch information
wenshao committed Aug 29, 2023
1 parent 739e374 commit 8d5bbf4
Showing 1 changed file with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.alibaba.fastjson2.features;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONFactory;
import com.alibaba.fastjson2.JSONReader;
import org.junit.jupiter.api.Test;

import java.util.HashMap;

import static com.alibaba.fastjson2.JSONReader.Feature.IgnoreNullPropertyValue;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class IgnoreNullPropertyValueTest {
@Test
public void test() {
String str = "{\"val\":null}";
assertTrue(JSON.parseObject(str, IgnoreNullPropertyValue).isEmpty());

{
HashMap<Object, Object> map = new HashMap<>();
JSONReader.of(str).read(map, IgnoreNullPropertyValue.mask);
assertTrue(map.isEmpty());
}

{
HashMap<Object, Object> map = new HashMap<>();
JSONReader.of(str, JSONFactory.createReadContext(IgnoreNullPropertyValue)).read(map, 0);
assertTrue(map.isEmpty());
}
}
}

0 comments on commit 8d5bbf4

Please sign in to comment.