forked from FasterXML/jackson-databind
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIsGetterBoolean3609Test.java
57 lines (42 loc) · 1.72 KB
/
IsGetterBoolean3609Test.java
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
package com.fasterxml.jackson.databind.introspect;
import com.fasterxml.jackson.databind.BaseMapTest;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.exc.InvalidDefinitionException;
import java.util.Collections;
import java.util.Map;
import static com.fasterxml.jackson.databind.MapperFeature.ALLOW_IS_GETTERS_FOR_NON_BOOLEAN;
public class IsGetterBoolean3609Test extends BaseMapTest {
static class POJO3609 {
int isEnabled;
protected POJO3609() { }
public POJO3609(int b) {
isEnabled = b;
}
public int isEnabled() { return isEnabled; }
public void setEnabled(int b) { isEnabled = b; }
}
public void testAllowIntIsGetter() throws Exception
{
ObjectMapper MAPPER = jsonMapperBuilder()
.enable(ALLOW_IS_GETTERS_FOR_NON_BOOLEAN)
.build();
POJO3609 input = new POJO3609(12);
final String json = MAPPER.writeValueAsString(input);
Map<?, ?> props = MAPPER.readValue(json, Map.class);
assertEquals(Collections.singletonMap("enabled", 12),
props);
POJO3609 output = MAPPER.readValue(json, POJO3609.class);
assertEquals(input.isEnabled, output.isEnabled);
}
public void testDisallowIntIsGetter() throws Exception
{
ObjectMapper MAPPER = jsonMapperBuilder()
.disable(ALLOW_IS_GETTERS_FOR_NON_BOOLEAN)
.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS)
.build();
POJO3609 input = new POJO3609(12);
final String json = MAPPER.writeValueAsString(input);
assertEquals("{}", json);
}
}