Skip to content

Commit

Permalink
Add unit test for #877; can not replicate the issue
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed May 4, 2016
1 parent 3cabf85 commit 7a69571
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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
*/
Expand All @@ -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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ protected JsonSerializer<Object> 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);
Expand Down Expand Up @@ -569,7 +569,7 @@ protected List<BeanPropertyWriter> findBeanProperties(SerializerProvider prov,
List<BeanPropertyDefinition> 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...
Expand Down Expand Up @@ -658,7 +658,7 @@ protected List<BeanPropertyWriter> 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<BeanPropertyWriter> props = builder.getProperties();
boolean includeByDefault = config.isEnabled(MapperFeature.DEFAULT_VIEW_INCLUSION);
final int propCount = props.size();
Expand Down Expand Up @@ -737,7 +737,7 @@ protected void removeSetterlessGetters(SerializationConfig config, BeanDescripti
Iterator<BeanPropertyDefinition> 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.*;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.databind.*;

/**
Expand All @@ -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<String,Object> result = writeAndMap(mapper, new Exception(TEST));
Map<String,Object> result = writeAndMap(MAPPER, new Exception(TEST));
// JDK 7 has introduced a new property 'suppressed' to Throwable
Object ob = result.get("suppressed");
if (ob != null) {
Expand All @@ -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<String,Object> 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"));
}
}

0 comments on commit 7a69571

Please sign in to comment.