blob: 3c2f9e38b72e636f2769947bd9b42ae733ebe02c (
plain)
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
69
70
71
72
73
74
75
76
|
package com.fasterxml.jackson.databind.deser;
import com.fasterxml.jackson.annotation.*;
import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility;
import com.fasterxml.jackson.databind.*;
/**
* Unit tests for checking handling of DeserializationConfig.
*/
public class TestConfig
extends BaseMapTest
{
@JsonAutoDetect(setterVisibility=Visibility.NONE)
final static class Dummy { }
final static class EmptyDummy { }
static class AnnoBean {
int value = 3;
@JsonProperty("y")
public void setX(int v) { value = v; }
}
/*
/**********************************************************
/* Main tests
/**********************************************************
*/
public void testDefaults()
{
ObjectMapper m = new ObjectMapper();
DeserializationConfig cfg = m.getDeserializationConfig();
// Expected defaults:
assertTrue(cfg.isEnabled(MapperFeature.USE_ANNOTATIONS));
assertTrue(cfg.isEnabled(MapperFeature.AUTO_DETECT_SETTERS));
assertTrue(cfg.isEnabled(MapperFeature.AUTO_DETECT_CREATORS));
assertTrue(cfg.isEnabled(MapperFeature.USE_GETTERS_AS_SETTERS));
assertTrue(cfg.isEnabled(MapperFeature.CAN_OVERRIDE_ACCESS_MODIFIERS));
assertFalse(cfg.isEnabled(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS));
assertFalse(cfg.isEnabled(DeserializationFeature.USE_BIG_INTEGER_FOR_INTS));
assertTrue(cfg.isEnabled(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES));
}
public void testOverrideIntrospectors()
{
ObjectMapper m = new ObjectMapper();
DeserializationConfig cfg = m.getDeserializationConfig();
// and finally, ensure we could override introspectors
cfg = cfg.withClassIntrospector(null); // no way to verify tho
cfg = cfg.withAnnotationIntrospector(null);
assertNull(cfg.getAnnotationIntrospector());
}
public void testAnnotationsDisabled() throws Exception
{
// first: verify that annotation introspection is enabled by default
ObjectMapper m = new ObjectMapper();
assertTrue(m.getDeserializationConfig().isEnabled(MapperFeature.USE_ANNOTATIONS));
// with annotations, property is renamed
AnnoBean bean = m.readValue("{ \"y\" : 0 }", AnnoBean.class);
assertEquals(0, bean.value);
m = new ObjectMapper();
m.configure(MapperFeature.USE_ANNOTATIONS, false);
// without annotations, should default to default bean-based name...
bean = m.readValue("{ \"x\" : 0 }", AnnoBean.class);
assertEquals(0, bean.value);
}
}
|