Skip to content

Commit 7a69571

Browse files
committed
Add unit test for #877; can not replicate the issue
1 parent 3cabf85 commit 7a69571

File tree

3 files changed

+46
-37
lines changed

3 files changed

+46
-37
lines changed

src/main/java/com/fasterxml/jackson/databind/ser/BasicSerializerFactory.java

+3-31
Original file line numberDiff line numberDiff line change
@@ -389,16 +389,10 @@ protected final JsonSerializer<?> findSerializerByPrimaryType(SerializerProvider
389389
if (Map.Entry.class.isAssignableFrom(raw)) {
390390
// 18-Oct-2015, tatu: With 2.7, need to dig type info:
391391
JavaType mapEntryType = type.findSuperType(Map.Entry.class);
392-
392+
393393
// 28-Apr-2015, tatu: TypeFactory does it all for us already so
394-
JavaType kt = mapEntryType.containedType(0);
395-
if (kt == null) {
396-
kt = TypeFactory.unknownType();
397-
}
398-
JavaType vt = mapEntryType.containedType(1);
399-
if (vt == null) {
400-
vt = TypeFactory.unknownType();
401-
}
394+
JavaType kt = mapEntryType.containedTypeOrUnknown(0);
395+
JavaType vt = mapEntryType.containedTypeOrUnknown(1);
402396
return buildMapEntrySerializer(prov.getConfig(), type, beanDesc, staticTyping, kt, vt);
403397
}
404398
if (ByteBuffer.class.isAssignableFrom(raw)) {
@@ -909,16 +903,6 @@ protected JsonSerializer<?> buildIteratorSerializer(SerializationConfig config,
909903
return new IteratorSerializer(valueType, staticTyping, createTypeSerializer(config, valueType));
910904
}
911905

912-
@Deprecated // since 2.5
913-
protected JsonSerializer<?> buildIteratorSerializer(SerializationConfig config,
914-
JavaType type, BeanDescription beanDesc, boolean staticTyping) throws JsonMappingException
915-
{
916-
JavaType[] params = config.getTypeFactory().findTypeParameters(type, Iterator.class);
917-
JavaType vt = (params == null || params.length != 1) ?
918-
TypeFactory.unknownType() : params[0];
919-
return buildIteratorSerializer(config, type, beanDesc, staticTyping, vt);
920-
}
921-
922906
/**
923907
* @since 2.5
924908
*/
@@ -930,18 +914,6 @@ protected JsonSerializer<?> buildIterableSerializer(SerializationConfig config,
930914
return new IterableSerializer(valueType, staticTyping, createTypeSerializer(config, valueType));
931915
}
932916

933-
@Deprecated // since 2.5
934-
protected JsonSerializer<?> buildIterableSerializer(SerializationConfig config,
935-
JavaType type, BeanDescription beanDesc,
936-
boolean staticTyping)
937-
throws JsonMappingException
938-
{
939-
JavaType[] params = config.getTypeFactory().findTypeParameters(type, Iterable.class);
940-
JavaType vt = (params == null || params.length != 1) ?
941-
TypeFactory.unknownType() : params[0];
942-
return buildIterableSerializer(config, type, beanDesc, staticTyping, vt);
943-
}
944-
945917
/**
946918
* @since 2.5
947919
*/

src/main/java/com/fasterxml/jackson/databind/ser/BeanSerializerFactory.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ protected JsonSerializer<Object> constructBeanSerializer(SerializerProvider prov
407407
// Any properties to suppress?
408408
props = filterBeanProperties(config, beanDesc, props);
409409

410-
// [JACKSON-440] Need to allow reordering of properties to serialize
410+
// Need to allow reordering of properties to serialize
411411
if (_factoryConfig.hasSerializerModifiers()) {
412412
for (BeanSerializerModifier mod : _factoryConfig.serializerModifiers()) {
413413
props = mod.orderProperties(config, beanDesc, props);
@@ -569,7 +569,7 @@ protected List<BeanPropertyWriter> findBeanProperties(SerializerProvider prov,
569569
List<BeanPropertyDefinition> properties = beanDesc.findProperties();
570570
final SerializationConfig config = prov.getConfig();
571571

572-
// [JACKSON-429]: ignore specified types
572+
// ignore specified types
573573
removeIgnorableTypes(config, beanDesc, properties);
574574

575575
// and possibly remove ones without matching mutator...
@@ -658,7 +658,7 @@ protected List<BeanPropertyWriter> filterBeanProperties(SerializationConfig conf
658658
*/
659659
protected void processViews(SerializationConfig config, BeanSerializerBuilder builder)
660660
{
661-
// [JACKSON-232]: whether non-annotated fields are included by default or not is configurable
661+
// whether non-annotated fields are included by default or not is configurable
662662
List<BeanPropertyWriter> props = builder.getProperties();
663663
boolean includeByDefault = config.isEnabled(MapperFeature.DEFAULT_VIEW_INCLUSION);
664664
final int propCount = props.size();
@@ -737,7 +737,7 @@ protected void removeSetterlessGetters(SerializationConfig config, BeanDescripti
737737
Iterator<BeanPropertyDefinition> it = properties.iterator();
738738
while (it.hasNext()) {
739739
BeanPropertyDefinition property = it.next();
740-
// one caveat: as per [JACKSON-806], only remove implicit properties;
740+
// one caveat: only remove implicit properties;
741741
// explicitly annotated ones should remain
742742
if (!property.couldDeserialize() && !property.isExplicitlyIncluded()) {
743743
it.remove();

src/test/java/com/fasterxml/jackson/databind/ser/TestExceptionSerialization.java

+39-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.util.*;
44

5+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
56
import com.fasterxml.jackson.databind.*;
67

78
/**
@@ -10,17 +11,31 @@
1011
public class TestExceptionSerialization
1112
extends BaseMapTest
1213
{
14+
@SuppressWarnings("serial")
15+
@JsonIgnoreProperties({ "bogus1" })
16+
static class ExceptionWithIgnoral extends RuntimeException
17+
{
18+
public int bogus1 = 3;
19+
20+
public int bogus2 = 5;
21+
22+
public ExceptionWithIgnoral(String msg) {
23+
super(msg);
24+
}
25+
}
26+
1327
/*
1428
/**********************************************************
1529
/* Tests
1630
/**********************************************************
1731
*/
1832

33+
private final ObjectMapper MAPPER = new ObjectMapper();
34+
1935
public void testSimple() throws Exception
2036
{
21-
ObjectMapper mapper = new ObjectMapper();
2237
String TEST = "test exception";
23-
Map<String,Object> result = writeAndMap(mapper, new Exception(TEST));
38+
Map<String,Object> result = writeAndMap(MAPPER, new Exception(TEST));
2439
// JDK 7 has introduced a new property 'suppressed' to Throwable
2540
Object ob = result.get("suppressed");
2641
if (ob != null) {
@@ -39,4 +54,26 @@ public void testSimple() throws Exception
3954
fail("Expected a List for exception member 'stackTrace', got: "+traces);
4055
}
4156
}
57+
58+
// for [databind#877]
59+
public void testIgnorals() throws Exception
60+
{
61+
// First, should ignore anything with class annotations
62+
String json = MAPPER
63+
.writeValueAsString(new ExceptionWithIgnoral("foobar"));
64+
65+
@SuppressWarnings("unchecked")
66+
Map<String,Object> result = MAPPER.readValue(json, Map.class);
67+
assertEquals("foobar", result.get("message"));
68+
69+
assertNull(result.get("bogus1"));
70+
assertNotNull(result.get("bogus2"));
71+
72+
// and then also remova second property with config overrides
73+
ObjectMapper mapper = new ObjectMapper();
74+
mapper.configOverride(ExceptionWithIgnoral.class)
75+
.setIgnorals(JsonIgnoreProperties.Value.forIgnoredProperties("bogus2"));
76+
assertNull(result.get("bogus1"));
77+
assertNotNull(result.get("bogus2"));
78+
}
4279
}

0 commit comments

Comments
 (0)