Skip to content

Commit 1c68f96

Browse files
committed
Add test for #1223
1 parent ae22865 commit 1c68f96

File tree

3 files changed

+58
-32
lines changed

3 files changed

+58
-32
lines changed

src/main/java/com/fasterxml/jackson/databind/introspect/POJOPropertiesCollector.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ protected POJOPropertiesCollector(MapperConfig<?> config, boolean forSerializati
127127
_config.getDefaultVisibilityChecker());
128128
}
129129
}
130-
130+
131131
/*
132132
/**********************************************************
133133
/* Public API

src/main/java/com/fasterxml/jackson/databind/introspect/VisibilityChecker.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -241,11 +241,11 @@ public Std with(JsonAutoDetect ann)
241241
{
242242
Std curr = this;
243243
if (ann != null) {
244-
curr = curr.withGetterVisibility(ann.getterVisibility());
245-
curr = curr.withIsGetterVisibility(ann.isGetterVisibility());
246-
curr = curr.withSetterVisibility(ann.setterVisibility());
247-
curr = curr.withCreatorVisibility(ann.creatorVisibility());
248-
curr = curr.withFieldVisibility(ann.fieldVisibility());
244+
curr = curr.withGetterVisibility(ann.getterVisibility());
245+
curr = curr.withIsGetterVisibility(ann.isGetterVisibility());
246+
curr = curr.withSetterVisibility(ann.setterVisibility());
247+
curr = curr.withCreatorVisibility(ann.creatorVisibility());
248+
curr = curr.withFieldVisibility(ann.fieldVisibility());
249249
}
250250
return curr;
251251
}

src/test/java/com/fasterxml/jackson/databind/ser/TestFeatures.java renamed to src/test/java/com/fasterxml/jackson/databind/ser/SerializationFeaturesTest.java

+52-26
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,18 @@
55

66
import com.fasterxml.jackson.core.JsonGenerator;
77
import com.fasterxml.jackson.databind.*;
8+
import com.fasterxml.jackson.databind.introspect.BasicBeanDescription;
9+
import com.fasterxml.jackson.databind.introspect.BeanPropertyDefinition;
810
import com.fasterxml.jackson.annotation.*;
911
import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility;
1012

1113
/**
12-
* Unit tests for checking whether JsonSerializerFactory.Feature
13-
* configuration works
14+
* Unit tests for checking handling of some of {@link MapperFeature}s
15+
* and {@link SerializationFeature}s for serialization.
1416
*/
15-
public class TestFeatures
17+
public class SerializationFeaturesTest
1618
extends BaseMapTest
1719
{
18-
/*
19-
/**********************************************************
20-
/* Helper classes
21-
/**********************************************************
22-
*/
23-
2420
/**
2521
* Class with one explicitly defined getter, one name-based
2622
* auto-detectable getter.
@@ -192,49 +188,47 @@ public void testFlushingAutomatic() throws IOException
192188
assertTrue(mapper.getSerializationConfig().isEnabled(SerializationFeature.FLUSH_AFTER_WRITE_VALUE));
193189
// default is to flush after writeValue()
194190
StringWriter sw = new StringWriter();
195-
JsonGenerator jgen = mapper.getFactory().createGenerator(sw);
196-
mapper.writeValue(jgen, Integer.valueOf(13));
191+
JsonGenerator g = mapper.getFactory().createGenerator(sw);
192+
mapper.writeValue(g, Integer.valueOf(13));
197193
assertEquals("13", sw.toString());
198-
jgen.close();
194+
g.close();
199195

200196
// ditto with ObjectWriter
201197
sw = new StringWriter();
202-
jgen = mapper.getFactory().createGenerator(sw);
198+
g = mapper.getFactory().createGenerator(sw);
203199
ObjectWriter ow = mapper.writer();
204-
ow.writeValue(jgen, Integer.valueOf(99));
200+
ow.writeValue(g, Integer.valueOf(99));
205201
assertEquals("99", sw.toString());
206-
jgen.close();
202+
g.close();
207203
}
208204

209-
// Test for [JACKSON-401]
210205
public void testFlushingNotAutomatic() throws IOException
211206
{
212207
// but should not occur if configured otherwise
213208
ObjectMapper mapper = new ObjectMapper();
214209
mapper.configure(SerializationFeature.FLUSH_AFTER_WRITE_VALUE, false);
215210
StringWriter sw = new StringWriter();
216-
JsonGenerator jgen = mapper.getFactory().createGenerator(sw);
211+
JsonGenerator g = mapper.getFactory().createGenerator(sw);
217212

218-
mapper.writeValue(jgen, Integer.valueOf(13));
213+
mapper.writeValue(g, Integer.valueOf(13));
219214
// no flushing now:
220215
assertEquals("", sw.toString());
221216
// except when actually flushing
222-
jgen.flush();
217+
g.flush();
223218
assertEquals("13", sw.toString());
224-
jgen.close();
219+
g.close();
225220
// Also, same should happen with ObjectWriter
226221
sw = new StringWriter();
227-
jgen = mapper.getFactory().createGenerator(sw);
222+
g = mapper.getFactory().createGenerator(sw);
228223
ObjectWriter ow = mapper.writer();
229-
ow.writeValue(jgen, Integer.valueOf(99));
224+
ow.writeValue(g, Integer.valueOf(99));
230225
assertEquals("", sw.toString());
231226
// except when actually flushing
232-
jgen.flush();
227+
g.flush();
233228
assertEquals("99", sw.toString());
234-
jgen.close();
229+
g.close();
235230
}
236231

237-
// Test for [JACKSON-805]
238232
public void testSingleElementCollections() throws IOException
239233
{
240234
final ObjectWriter writer = objectWriter().with(SerializationFeature.WRITE_SINGLE_ELEM_ARRAYS_UNWRAPPED);
@@ -264,6 +258,38 @@ public void testSingleElementCollections() throws IOException
264258
assertEquals("true", writer.writeValueAsString(new Boolean[] { Boolean.TRUE }));
265259
assertEquals("3", writer.writeValueAsString(new int[] { 3 }));
266260
assertEquals(quote("foo"), writer.writeValueAsString(new String[] { "foo" }));
267-
261+
}
262+
263+
static class TCls {
264+
@JsonProperty("groupname")
265+
private String groupname;
266+
267+
public void setName(String str) {
268+
this.groupname = str;
269+
}
270+
public String getName() {
271+
return groupname;
272+
}
273+
}
274+
275+
public void testVisibilityFeatures() throws Exception
276+
{
277+
ObjectMapper om = new ObjectMapper();
278+
// Only use explicitly specified values to be serialized/deserialized (i.e., JSONProperty).
279+
om.configure(MapperFeature.AUTO_DETECT_FIELDS, false);
280+
om.configure(MapperFeature.AUTO_DETECT_GETTERS, false);
281+
om.configure(MapperFeature.AUTO_DETECT_SETTERS, false);
282+
om.configure(MapperFeature.AUTO_DETECT_IS_GETTERS, false);
283+
om.configure(MapperFeature.USE_GETTERS_AS_SETTERS, false);
284+
om.configure(MapperFeature.CAN_OVERRIDE_ACCESS_MODIFIERS, true);
285+
om.configure(MapperFeature.INFER_PROPERTY_MUTATORS, false);
286+
om.configure(MapperFeature.USE_ANNOTATIONS, true);
287+
288+
JavaType javaType = om.getTypeFactory().constructType(TCls.class);
289+
BeanDescription desc = (BeanDescription) om.getSerializationConfig().introspect(javaType);
290+
List<BeanPropertyDefinition> props = desc.findProperties();
291+
if (props.size() != 1) {
292+
fail("Should find 1 property, not "+props.size()+"; properties = "+props);
293+
}
268294
}
269295
}

0 commit comments

Comments
 (0)