Skip to content

Commit 1904839

Browse files
committed
Fix #1368
1 parent e4b261e commit 1904839

File tree

5 files changed

+41
-1
lines changed

5 files changed

+41
-1
lines changed

release-notes/CREDITS

+5
Original file line numberDiff line numberDiff line change
@@ -471,3 +471,8 @@ Brian Pontarelli (voidmain@github)
471471
Max Drobotov (fizmax@github)
472472
* Reported, contributed fix for #1332: `ArrayIndexOutOfBoundException` for enum by index deser
473473
(2.7.7)
474+
475+
Josh Caplan (jecaplan@github)
476+
* Reported, suggested fix for #1368: Problem serializing `JsonMappingException` due to addition
477+
of non-ignored `processor` property (added in 2.7)
478+
(2.7.8)

release-notes/VERSION

+3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ Project: jackson-databind
1010
#1359: Improve `JsonNode` deserializer to create `FloatNode` if parser supports
1111
#1362: ObjectReader.readValues()` ignores offset and length when reading an array
1212
(reported by wastevenson@github)
13+
#1368: Problem serializing `JsonMappingException` due to addition of non-ignored
14+
`processor` property (added in 2.7)
15+
(reported, suggesed fix by Josh C)
1316

1417
2.7.7 (27-Aug-2016)
1518

src/main/java/com/fasterxml/jackson/databind/JsonMappingException.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import java.io.Serializable;
66
import java.util.*;
77

8+
import com.fasterxml.jackson.annotation.JsonIgnore;
89
import com.fasterxml.jackson.core.*;
910
import com.fasterxml.jackson.databind.util.ClassUtil;
1011

@@ -400,7 +401,7 @@ public List<Reference> getPath()
400401
}
401402

402403
/**
403-
* Method for accesing description of path that lead to the
404+
* Method for accessing description of path that lead to the
404405
* problem that triggered this exception
405406
*/
406407
public String getPathReference()
@@ -454,6 +455,7 @@ public void prependPath(Reference r)
454455
*/
455456

456457
@Override // since 2.7.5
458+
@JsonIgnore // as per [databind#1368]
457459
public Object getProcessor() { return _processor; }
458460

459461
@Override

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

+1
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,7 @@ protected List<BeanPropertyWriter> findBeanProperties(SerializerProvider prov,
587587
ArrayList<BeanPropertyWriter> result = new ArrayList<BeanPropertyWriter>(properties.size());
588588
final boolean fixAccess = config.canOverrideAccessModifiers();
589589
final boolean forceAccess = fixAccess && config.isEnabled(MapperFeature.OVERRIDE_PUBLIC_ACCESS_MODIFIERS);
590+
590591
for (BeanPropertyDefinition property : properties) {
591592
final AnnotatedMember accessor = property.getAccessor();
592593
// Type id? Requires special handling:

src/test/java/com/fasterxml/jackson/databind/deser/TestExceptionDeserialization.java

+29
Original file line numberDiff line numberDiff line change
@@ -136,4 +136,33 @@ public void testSingleValueArrayDeserializationException() throws Exception {
136136
//Exception thrown correctly
137137
}
138138
}
139+
140+
static class NoSerdeConstructor {
141+
private String strVal;
142+
public String getVal() { return strVal; }
143+
public NoSerdeConstructor( String strVal ) {
144+
this.strVal = strVal;
145+
}
146+
}
147+
148+
// [databind#1368]
149+
public void testFailingNoSerdeConstructor() throws IOException {
150+
Exception e = null;
151+
// cant deserialize due to unexpected constructor
152+
try {
153+
MAPPER.readValue( "{ \"val\": \"foo\" }", NoSerdeConstructor.class );
154+
fail("Should not pass");
155+
} catch (JsonMappingException e0) {
156+
verifyException(e0, "No suitable constructor");
157+
e = e0;
158+
}
159+
// but should be able to serialize new exception we got
160+
String json = MAPPER.writeValueAsString(e);
161+
JsonNode root = MAPPER.readTree(json);
162+
String msg = root.path("message").asText();
163+
String MATCH = "No suitable constructor";
164+
if (!msg.contains(MATCH)) {
165+
fail("Exception should contain '"+MATCH+"', does not: '"+msg+"'");
166+
}
167+
}
139168
}

0 commit comments

Comments
 (0)