blob: f056ab258059975f887f265755fa3e6f4cc8fde9 [file] [log] [blame]
Tatu Salorantaa63c2032011-12-24 00:26:53 -08001package com.fasterxml.jackson.databind.ser;
2
Tatu Salorantaa63c2032011-12-24 00:26:53 -08003import java.util.*;
4
5import com.fasterxml.jackson.databind.*;
6
7/**
8 * Unit tests for verifying that simple exceptions can be serialized.
9 */
10public class TestExceptionSerialization
11 extends BaseMapTest
12{
13 /*
Tatu Salorantaf3bb3422012-03-20 16:20:01 -070014 /**********************************************************
15 /* Tests
16 /**********************************************************
Tatu Salorantaa63c2032011-12-24 00:26:53 -080017 */
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 Salorantaf3bb3422012-03-20 16:20:01 -070024 // 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 Salorantaa63c2032011-12-24 00:26:53 -080032 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}