Skip to content

Commit c41b4af

Browse files
committed
Add test cases
for FasterXML#5139
1 parent 51f4804 commit c41b4af

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package com.fasterxml.jackson.databind.deser.std;
2+
3+
import com.fasterxml.jackson.annotation.JsonSetter;
4+
import com.fasterxml.jackson.annotation.Nulls;
5+
import com.fasterxml.jackson.core.JsonProcessingException;
6+
import com.fasterxml.jackson.core.type.TypeReference;
7+
import com.fasterxml.jackson.databind.ObjectMapper;
8+
import com.fasterxml.jackson.databind.exc.InvalidNullException;
9+
import org.junit.jupiter.api.Test;
10+
11+
import java.util.List;
12+
13+
import static org.junit.jupiter.api.Assertions.assertThrows;
14+
import static org.junit.jupiter.api.Assertions.assertTrue;
15+
16+
public class CollectionDeserializer5139Test {
17+
static class Dst {
18+
private List<Integer> list;
19+
20+
public List<Integer> getList() {
21+
return list;
22+
}
23+
24+
public void setList(List<Integer> list) {
25+
this.list = list;
26+
}
27+
}
28+
29+
@Test
30+
public void nullsFailTest() {
31+
ObjectMapper mapper = new ObjectMapper();
32+
mapper.configOverride(List.class).setSetterInfo(JsonSetter.Value.forContentNulls(Nulls.FAIL));
33+
34+
assertThrows(
35+
InvalidNullException.class,
36+
() -> mapper.readValue("{\"list\":[\"\"]}", new TypeReference<Dst>(){})
37+
);
38+
}
39+
40+
@Test
41+
public void nullsSkipTest() throws JsonProcessingException {
42+
ObjectMapper mapper = new ObjectMapper();
43+
mapper.configOverride(List.class).setSetterInfo(JsonSetter.Value.forContentNulls(Nulls.SKIP));
44+
45+
Dst dst = mapper.readValue("{\"list\":[\"\"]}", new TypeReference<>() {});
46+
47+
assertTrue(dst.getList().isEmpty());
48+
}
49+
}

0 commit comments

Comments
 (0)