blob: 0fb1e5cb95498ded49698b11e5517644b3f598dc (
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
|
package com.fasterxml.jackson.databind.deser;
import java.util.*;
import com.fasterxml.jackson.annotation.*;
import com.fasterxml.jackson.databind.*;
public class ReadOnlyListDeser2118Test extends BaseMapTest
{
// [databind#2118]
static class SecurityGroup {
List<SecurityGroupRule> securityGroupRules;
public SecurityGroup() {
this.securityGroupRules = new ArrayList<>();
}
@JsonProperty(value="security_group_rules", access=JsonProperty.Access.READ_ONLY)
public List<SecurityGroupRule> getSecurityGroupRules() {
return securityGroupRules;
}
public SecurityGroup setSecurityGroupRules(List<SecurityGroupRule> securityGroupRules) {
throw new Error("Should not be called");
}
}
static class SecurityGroupRule {
private String id;
public SecurityGroupRule() { }
@JsonProperty
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
@Override
public String toString() {
return "{SecurityGroupRule '"+id+"'}";
}
}
private final ObjectMapper mapper = newJsonMapper();
// [databind#2118]
public void testAccessReadOnly() throws Exception {
String data ="{\"security_group_rules\": [{\"id\": \"id1\"}]}";
// This would work around the issue:
// mapper.disable(MapperFeature.USE_GETTERS_AS_SETTERS);
SecurityGroup sg = mapper.readValue(data, SecurityGroup.class);
assertEquals(Collections.emptyList(), sg.securityGroupRules);
}
}
|