Tatu Saloranta | a63c203 | 2011-12-24 00:26:53 -0800 | [diff] [blame] | 1 | package com.fasterxml.jackson.databind.ser; |
| 2 | |
Tatu Saloranta | a63c203 | 2011-12-24 00:26:53 -0800 | [diff] [blame] | 3 | import java.util.*; |
| 4 | |
| 5 | import com.fasterxml.jackson.databind.*; |
| 6 | |
| 7 | /** |
| 8 | * Unit tests for verifying that simple exceptions can be serialized. |
| 9 | */ |
| 10 | public class TestExceptionSerialization |
| 11 | extends BaseMapTest |
| 12 | { |
| 13 | /* |
Tatu Saloranta | f3bb342 | 2012-03-20 16:20:01 -0700 | [diff] [blame^] | 14 | /********************************************************** |
| 15 | /* Tests |
| 16 | /********************************************************** |
Tatu Saloranta | a63c203 | 2011-12-24 00:26:53 -0800 | [diff] [blame] | 17 | */ |
| 18 | |
| 19 | public void testSimple() throws Exception |
| 20 | { |
| 21 | ObjectMapper mapper = new ObjectMapper(); |
| 22 | String TEST = "test exception"; |
| 23 | Map<String,Object> result = writeAndMap(mapper, new Exception(TEST)); |
Tatu Saloranta | f3bb342 | 2012-03-20 16:20:01 -0700 | [diff] [blame^] | 24 | // JDK 7 has introduced a new property 'suppressed' to Throwable |
| 25 | Object ob = result.get("suppressed"); |
| 26 | if (ob != null) { |
| 27 | assertEquals(5, result.size()); |
| 28 | } else { |
| 29 | assertEquals(4, result.size()); |
| 30 | } |
| 31 | |
Tatu Saloranta | a63c203 | 2011-12-24 00:26:53 -0800 | [diff] [blame] | 32 | assertEquals(TEST, result.get("message")); |
| 33 | assertNull(result.get("cause")); |
| 34 | assertEquals(TEST, result.get("localizedMessage")); |
| 35 | |
| 36 | // hmmh. what should we get for stack traces? |
| 37 | Object traces = result.get("stackTrace"); |
| 38 | if (!(traces instanceof List<?>)) { |
| 39 | fail("Expected a List for exception member 'stackTrace', got: "+traces); |
| 40 | } |
| 41 | } |
| 42 | } |