Skip to content

Commit 5b8de22

Browse files
committed
Add a (failing) test for #736
1 parent f4a65cb commit 5b8de22

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package com.fasterxml.jackson.failing;
2+
3+
import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility;
4+
import com.fasterxml.jackson.annotation.PropertyAccessor;
5+
import com.fasterxml.jackson.databind.*;
6+
7+
public class RequireSetterForGetter736Test extends BaseMapTest
8+
{
9+
public static class DataB {
10+
private int readonly;
11+
private int readwrite;
12+
13+
public DataB() {
14+
readonly = 1;
15+
readwrite = 2;
16+
}
17+
18+
public int getReadwrite() {
19+
return readwrite;
20+
}
21+
public void setReadwrite(int readwrite) {
22+
this.readwrite = readwrite;
23+
}
24+
public int getReadonly() {
25+
return readonly;
26+
}
27+
}
28+
29+
// for [databind#736]
30+
public void testNeedForSetters() throws Exception
31+
{
32+
ObjectMapper mapper = new ObjectMapper();
33+
mapper.setVisibility(PropertyAccessor.ALL, Visibility.NONE);
34+
mapper.setVisibility(PropertyAccessor.GETTER, Visibility.PUBLIC_ONLY);
35+
mapper.setVisibility(PropertyAccessor.SETTER, Visibility.PUBLIC_ONLY);
36+
mapper.enable(MapperFeature.REQUIRE_SETTERS_FOR_GETTERS);
37+
DataB dataB = new DataB();
38+
39+
String json = mapper.writeValueAsString(dataB);
40+
assertEquals(aposToQuotes("{'readwrite':2}"), json);
41+
42+
}
43+
}

0 commit comments

Comments
 (0)