1 package com.thoughtworks.xstream.converters.extended; 2 3 import com.thoughtworks.xstream.converters.Converter; 4 import com.thoughtworks.xstream.converters.MarshallingContext; 5 import com.thoughtworks.xstream.converters.UnmarshallingContext; 6 import com.thoughtworks.xstream.io.HierarchicalStreamReader; 7 import com.thoughtworks.xstream.io.HierarchicalStreamWriter; 8 9 import java.lang.reflect.InvocationTargetException ; 10 import java.util.ArrayList ; 11 import java.util.List ; 12 13 19 public class ThrowableConverter implements Converter { 20 21 private Converter defaultConverter; 22 23 public ThrowableConverter(Converter defaultConverter) { 24 this.defaultConverter = defaultConverter; 25 } 26 27 public boolean canConvert(final Class type) { 28 return Throwable .class.isAssignableFrom(type); 29 } 30 31 public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) { 32 Throwable throwable = (Throwable ) source; 33 throwable.getStackTrace(); defaultConverter.marshal(throwable, writer, context); 35 } 36 37 public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { 38 return defaultConverter.unmarshal(reader, context); 39 } 40 } 41 | Popular Tags |