-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathJsonNullWithEmptyTest.java
More file actions
68 lines (55 loc) · 2.39 KB
/
JsonNullWithEmptyTest.java
File metadata and controls
68 lines (55 loc) · 2.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package org.openapitools.jackson.nullable;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
class JsonNullWithEmptyTest extends ModuleTestBase
{
private final ObjectMapper MAPPER = mapperWithModule();
private final ObjectMapper MAPPER_BLANK_TO_NULL = mapperWithModule(new JsonNullableModule().mapBlankStringToNull(true));
static class BooleanBean {
public JsonNullable<Boolean> value;
public BooleanBean() { }
public BooleanBean(Boolean b) {
value = JsonNullable.of(b);
}
}
// default behavior (mapBlankStringToNull = false)
@Test
void testJsonNullableFromEmpty() throws Exception {
JsonNullable<?> value = MAPPER.readValue(quote(""), new TypeReference<JsonNullable<Integer>>() {});
assertFalse(value.isPresent());
}
// for [datatype-jdk8#23]
@Test
void testBooleanWithEmpty() throws Exception {
// and looks like a special, somewhat non-conforming case is what a user had
// issues with
BooleanBean b = MAPPER.readValue(aposToQuotes("{'value':''}"), BooleanBean.class);
assertNotNull(b.value);
assertFalse(b.value.isPresent());
}
// mapBlankStringToNull = true
@Test
void testJsonNullableFromEmptyWithMapBlankStringToNull() throws Exception {
JsonNullable<?> value = MAPPER_BLANK_TO_NULL.readValue(quote(""), new TypeReference<JsonNullable<Integer>>() {});
assertTrue(value.isPresent());
assertNull(value.get());
}
@Test
void testJsonNullableFromBlankWithMapBlankStringToNull() throws Exception {
JsonNullable<?> value = MAPPER_BLANK_TO_NULL.readValue(quote(" "), new TypeReference<JsonNullable<Integer>>() {});
assertTrue(value.isPresent());
assertNull(value.get());
}
@Test
void testBooleanWithEmptyWithMapBlankStringToNull() throws Exception {
BooleanBean b = MAPPER_BLANK_TO_NULL.readValue(aposToQuotes("{'value':''}"), BooleanBean.class);
assertNotNull(b.value);
assertTrue(b.value.isPresent());
assertNull(b.value.get());
}
}