• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
DataB()13         public DataB() {
14             readonly = 1;
15             readwrite = 2;
16         }
17 
getReadwrite()18         public int getReadwrite() {
19             return readwrite;
20         }
setReadwrite(int readwrite)21         public void setReadwrite(int readwrite) {
22             this.readwrite = readwrite;
23         }
getReadonly()24         public int getReadonly() {
25             return readonly;
26         }
27     }
28 
29     // for [databind#736]
testNeedForSetters()30     public void testNeedForSetters() throws Exception
31     {
32         ObjectMapper mapper = jsonMapperBuilder()
33                 .visibility(PropertyAccessor.ALL, Visibility.NONE)
34                 .visibility(PropertyAccessor.FIELD, Visibility.NONE)
35                 .visibility(PropertyAccessor.GETTER, Visibility.PUBLIC_ONLY)
36                 .visibility(PropertyAccessor.SETTER, Visibility.PUBLIC_ONLY)
37                 .enable(MapperFeature.REQUIRE_SETTERS_FOR_GETTERS)
38                 .build();
39         DataB dataB = new DataB();
40 
41         String json = mapper.writeValueAsString(dataB);
42         assertEquals(aposToQuotes("{'readwrite':2}"), json);
43     }
44 }
45