Skip to content

Commit c07d935

Browse files
committed
backport test for #1890
1 parent 90ee9f5 commit c07d935

File tree

1 file changed

+108
-0
lines changed

1 file changed

+108
-0
lines changed
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
package com.fasterxml.jackson.failing;
2+
3+
import java.beans.ConstructorProperties;
4+
import java.io.IOException;
5+
6+
import com.fasterxml.jackson.annotation.JsonProperty;
7+
import com.fasterxml.jackson.databind.BaseMapTest;
8+
import com.fasterxml.jackson.databind.ObjectMapper;
9+
10+
public class ReadOnlyDeser1890Test
11+
extends BaseMapTest
12+
{
13+
public static class PersonAnnotations {
14+
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
15+
private TestEnum testEnum;
16+
private String name;
17+
18+
public PersonAnnotations() { }
19+
20+
@ConstructorProperties({"testEnum", "name"})
21+
public PersonAnnotations(TestEnum testEnum, String name) {
22+
this.testEnum = testEnum;
23+
this.name = name;
24+
}
25+
26+
public TestEnum getTestEnum() {
27+
return testEnum;
28+
}
29+
30+
public void setTestEnum(TestEnum testEnum) {
31+
this.testEnum = testEnum;
32+
}
33+
34+
public String getName() {
35+
return name;
36+
}
37+
38+
public void setName(String name) {
39+
this.name = name;
40+
}
41+
}
42+
43+
public static class Person {
44+
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
45+
private TestEnum testEnum;
46+
private String name;
47+
48+
public Person() {
49+
}
50+
51+
public Person(TestEnum testEnum, String name) {
52+
this.testEnum = testEnum;
53+
this.name = name;
54+
}
55+
56+
public TestEnum getTestEnum() {
57+
return testEnum;
58+
}
59+
60+
public void setTestEnum(TestEnum testEnum) {
61+
this.testEnum = testEnum;
62+
}
63+
64+
public String getName() {
65+
return name;
66+
}
67+
68+
public void setName(String name) {
69+
this.name = name;
70+
}
71+
}
72+
73+
enum TestEnum{
74+
TEST
75+
}
76+
77+
/*
78+
/**********************************************************
79+
/* Test methods
80+
/**********************************************************
81+
*/
82+
83+
private final ObjectMapper MAPPER = objectMapper();
84+
85+
public void testDeserializeAnnotationsOneField() throws IOException {
86+
PersonAnnotations person = MAPPER.readValue("{\"testEnum\":\"\"}", PersonAnnotations.class);
87+
assertNull(person.getTestEnum());
88+
}
89+
90+
public void testDeserializeAnnotationsTwoFields() throws IOException {
91+
PersonAnnotations person = MAPPER.readValue("{\"testEnum\":\"\",\"name\":\"changyong\"}",
92+
PersonAnnotations.class);
93+
assertNull(person.getTestEnum());
94+
assertEquals("changyong", person.getName());
95+
}
96+
97+
public void testDeserializeOneField() throws IOException {
98+
Person person = MAPPER.readValue("{\"testEnum\":\"\"}", Person.class);
99+
assertNull(person.getTestEnum());
100+
}
101+
102+
public void testDeserializeTwoFields() throws IOException {
103+
Person person = MAPPER.readValue("{\"testEnum\":\"\",\"name\":\"changyong\"}",
104+
Person.class);
105+
assertNull(person.getTestEnum());
106+
assertEquals("changyong", person.getName());
107+
}
108+
}

0 commit comments

Comments
 (0)