Skip to content

Jackson exceptions should be Jackson-serializable #1370

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 8 commits into from
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,7 @@ public void prependPath(Reference r)
/**********************************************************
*/

@JsonIgnore
@Override // since 2.7.5
public Object getProcessor() { return _processor; }

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.fasterxml.jackson.databind;

import java.io.IOException;

import org.junit.Test;

public class TestJsonMappingException {
public static class NoSerdeConstructor {
private String strVal;
public String getVal() { return strVal; }
public NoSerdeConstructor( String strVal ) {
this.strVal = strVal;
}
}
// we know we can't serialize this dumb class above
@Test( expected = JsonMappingException.class )
public void testNoSerdeConstructor() throws IOException {
ObjectMapper mpr = new ObjectMapper();
mpr.readValue( "{ \"val\": \"foo\" }", NoSerdeConstructor.class );
}
// we should, however, be able to serialize the exception arising from the above test
@Test
public void testJsonMappingExceptionIsJacksonSerializable() throws IOException {
ObjectMapper mpr = new ObjectMapper();
try {
testNoSerdeConstructor();
} catch ( JsonMappingException exc ) {
// without @JsonIgnore on getProcessor() this causes an error
mpr.writeValueAsString( exc );
}
}
}