diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/BasicSerializerFactory.java b/src/main/java/com/fasterxml/jackson/databind/ser/BasicSerializerFactory.java index fb3e010179..29c4a4900b 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/BasicSerializerFactory.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/BasicSerializerFactory.java @@ -389,16 +389,10 @@ protected final JsonSerializer findSerializerByPrimaryType(SerializerProvider if (Map.Entry.class.isAssignableFrom(raw)) { // 18-Oct-2015, tatu: With 2.7, need to dig type info: JavaType mapEntryType = type.findSuperType(Map.Entry.class); - + // 28-Apr-2015, tatu: TypeFactory does it all for us already so - JavaType kt = mapEntryType.containedType(0); - if (kt == null) { - kt = TypeFactory.unknownType(); - } - JavaType vt = mapEntryType.containedType(1); - if (vt == null) { - vt = TypeFactory.unknownType(); - } + JavaType kt = mapEntryType.containedTypeOrUnknown(0); + JavaType vt = mapEntryType.containedTypeOrUnknown(1); return buildMapEntrySerializer(prov.getConfig(), type, beanDesc, staticTyping, kt, vt); } if (ByteBuffer.class.isAssignableFrom(raw)) { @@ -909,16 +903,6 @@ protected JsonSerializer buildIteratorSerializer(SerializationConfig config, return new IteratorSerializer(valueType, staticTyping, createTypeSerializer(config, valueType)); } - @Deprecated // since 2.5 - protected JsonSerializer buildIteratorSerializer(SerializationConfig config, - JavaType type, BeanDescription beanDesc, boolean staticTyping) throws JsonMappingException - { - JavaType[] params = config.getTypeFactory().findTypeParameters(type, Iterator.class); - JavaType vt = (params == null || params.length != 1) ? - TypeFactory.unknownType() : params[0]; - return buildIteratorSerializer(config, type, beanDesc, staticTyping, vt); - } - /** * @since 2.5 */ @@ -930,18 +914,6 @@ protected JsonSerializer buildIterableSerializer(SerializationConfig config, return new IterableSerializer(valueType, staticTyping, createTypeSerializer(config, valueType)); } - @Deprecated // since 2.5 - protected JsonSerializer buildIterableSerializer(SerializationConfig config, - JavaType type, BeanDescription beanDesc, - boolean staticTyping) - throws JsonMappingException - { - JavaType[] params = config.getTypeFactory().findTypeParameters(type, Iterable.class); - JavaType vt = (params == null || params.length != 1) ? - TypeFactory.unknownType() : params[0]; - return buildIterableSerializer(config, type, beanDesc, staticTyping, vt); - } - /** * @since 2.5 */ diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/BeanSerializerFactory.java b/src/main/java/com/fasterxml/jackson/databind/ser/BeanSerializerFactory.java index 284759c57e..68929c02ea 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/BeanSerializerFactory.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/BeanSerializerFactory.java @@ -407,7 +407,7 @@ protected JsonSerializer constructBeanSerializer(SerializerProvider prov // Any properties to suppress? props = filterBeanProperties(config, beanDesc, props); - // [JACKSON-440] Need to allow reordering of properties to serialize + // Need to allow reordering of properties to serialize if (_factoryConfig.hasSerializerModifiers()) { for (BeanSerializerModifier mod : _factoryConfig.serializerModifiers()) { props = mod.orderProperties(config, beanDesc, props); @@ -569,7 +569,7 @@ protected List findBeanProperties(SerializerProvider prov, List properties = beanDesc.findProperties(); final SerializationConfig config = prov.getConfig(); - // [JACKSON-429]: ignore specified types + // ignore specified types removeIgnorableTypes(config, beanDesc, properties); // and possibly remove ones without matching mutator... @@ -658,7 +658,7 @@ protected List filterBeanProperties(SerializationConfig conf */ protected void processViews(SerializationConfig config, BeanSerializerBuilder builder) { - // [JACKSON-232]: whether non-annotated fields are included by default or not is configurable + // whether non-annotated fields are included by default or not is configurable List props = builder.getProperties(); boolean includeByDefault = config.isEnabled(MapperFeature.DEFAULT_VIEW_INCLUSION); final int propCount = props.size(); @@ -737,7 +737,7 @@ protected void removeSetterlessGetters(SerializationConfig config, BeanDescripti Iterator it = properties.iterator(); while (it.hasNext()) { BeanPropertyDefinition property = it.next(); - // one caveat: as per [JACKSON-806], only remove implicit properties; + // one caveat: only remove implicit properties; // explicitly annotated ones should remain if (!property.couldDeserialize() && !property.isExplicitlyIncluded()) { it.remove(); diff --git a/src/test/java/com/fasterxml/jackson/databind/ser/TestExceptionSerialization.java b/src/test/java/com/fasterxml/jackson/databind/ser/TestExceptionSerialization.java index f056ab2580..0d1dc0aaa6 100644 --- a/src/test/java/com/fasterxml/jackson/databind/ser/TestExceptionSerialization.java +++ b/src/test/java/com/fasterxml/jackson/databind/ser/TestExceptionSerialization.java @@ -2,6 +2,7 @@ import java.util.*; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.databind.*; /** @@ -10,17 +11,31 @@ public class TestExceptionSerialization extends BaseMapTest { + @SuppressWarnings("serial") + @JsonIgnoreProperties({ "bogus1" }) + static class ExceptionWithIgnoral extends RuntimeException + { + public int bogus1 = 3; + + public int bogus2 = 5; + + public ExceptionWithIgnoral(String msg) { + super(msg); + } + } + /* /********************************************************** /* Tests /********************************************************** */ + private final ObjectMapper MAPPER = new ObjectMapper(); + public void testSimple() throws Exception { - ObjectMapper mapper = new ObjectMapper(); String TEST = "test exception"; - Map result = writeAndMap(mapper, new Exception(TEST)); + Map result = writeAndMap(MAPPER, new Exception(TEST)); // JDK 7 has introduced a new property 'suppressed' to Throwable Object ob = result.get("suppressed"); if (ob != null) { @@ -39,4 +54,26 @@ public void testSimple() throws Exception fail("Expected a List for exception member 'stackTrace', got: "+traces); } } + + // for [databind#877] + public void testIgnorals() throws Exception + { + // First, should ignore anything with class annotations + String json = MAPPER + .writeValueAsString(new ExceptionWithIgnoral("foobar")); + + @SuppressWarnings("unchecked") + Map result = MAPPER.readValue(json, Map.class); + assertEquals("foobar", result.get("message")); + + assertNull(result.get("bogus1")); + assertNotNull(result.get("bogus2")); + + // and then also remova second property with config overrides + ObjectMapper mapper = new ObjectMapper(); + mapper.configOverride(ExceptionWithIgnoral.class) + .setIgnorals(JsonIgnoreProperties.Value.forIgnoredProperties("bogus2")); + assertNull(result.get("bogus1")); + assertNotNull(result.get("bogus2")); + } }