|
| 1 | +package com.fasterxml.jackson.databind.exc; |
| 2 | + |
| 3 | +import com.fasterxml.jackson.databind.BaseMapTest; |
| 4 | +import com.fasterxml.jackson.databind.ObjectMapper; |
| 5 | + |
| 6 | +// [databind#4071]: Ignore "message" for custom exceptions with only default constructor |
| 7 | +public class CustomExceptionDeser4071Test extends BaseMapTest |
| 8 | +{ |
| 9 | + static class CustomThrowable4071 extends Throwable { } |
| 10 | + |
| 11 | + static class CustomRuntimeException4071 extends RuntimeException { } |
| 12 | + |
| 13 | + static class CustomCheckedException4071 extends Exception { } |
| 14 | + |
| 15 | + private final ObjectMapper MAPPER = newJsonMapper(); |
| 16 | + |
| 17 | + public void testCustomException() throws Exception |
| 18 | + { |
| 19 | + String exStr = MAPPER.writeValueAsString(new CustomThrowable4071()); |
| 20 | + assertNotNull(MAPPER.readValue(exStr, CustomThrowable4071.class)); |
| 21 | + } |
| 22 | + |
| 23 | + public void testCustomRuntimeException() throws Exception |
| 24 | + { |
| 25 | + String exStr = MAPPER.writeValueAsString(new CustomRuntimeException4071()); |
| 26 | + assertNotNull(MAPPER.readValue(exStr, CustomRuntimeException4071.class)); |
| 27 | + } |
| 28 | + |
| 29 | + public void testCustomCheckedException() throws Exception |
| 30 | + { |
| 31 | + String exStr = MAPPER.writeValueAsString(new CustomCheckedException4071()); |
| 32 | + assertNotNull(MAPPER.readValue(exStr, CustomCheckedException4071.class)); |
| 33 | + } |
| 34 | + |
| 35 | + public void testDeserAsThrowable() throws Exception |
| 36 | + { |
| 37 | + _testDeserAsThrowable(MAPPER.writeValueAsString(new CustomRuntimeException4071())); |
| 38 | + _testDeserAsThrowable(MAPPER.writeValueAsString(new CustomCheckedException4071())); |
| 39 | + _testDeserAsThrowable(MAPPER.writeValueAsString(new CustomThrowable4071())); |
| 40 | + } |
| 41 | + |
| 42 | + private void _testDeserAsThrowable(String exStr) throws Exception |
| 43 | + { |
| 44 | + assertNotNull(MAPPER.readValue(exStr, Throwable.class)); |
| 45 | + } |
| 46 | +} |
0 commit comments