Skip to content

Instantly share code, notes, and snippets.

@ittaiz
Created March 13, 2015 20:29
Show Gist options
  • Save ittaiz/b59d90ccb9d27d07de2d to your computer and use it in GitHub Desktop.
Save ittaiz/b59d90ccb9d27d07de2d to your computer and use it in GitHub Desktop.
Jackson Custom exception regression issue
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.module.scala.DefaultScalaModule;
import org.junit.Test;
import java.io.IOException;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
public class JacksonRegressionTest {
@Test
public void jacksonRegressionTest() throws IOException {
SomeException ex = new SomeException("message");
ObjectMapper mapper = new ObjectMapper().registerModule(new DefaultScalaModule());
final String exceptionAsString = mapper.writeValueAsString(ex);
final SomeException someException = mapper.readValue(exceptionAsString, SomeException.class);
assertThat(someException.getMessage(), is("message"));
}
@SuppressWarnings("UnusedDeclaration")
public static class SomeException extends RuntimeException {
private Object[] args;
public SomeException(String message) {
super(message);
}
public SomeException(String message, Throwable cause, Object... args) {
super(message, cause);
this.args = args;
}
public SomeException(String message, Object... args) {
super(message);
this.args = args;
}
public Object[] getArgs() {
return args;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment