This repository has been archived by the owner on Feb 21, 2022. It is now read-only.
forked from x-stream/xstream
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use SerializationConverter as default for ThrowableConverter (closes x…
- Loading branch information
Showing
5 changed files
with
153 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,42 @@ | ||
/* | ||
* Copyright (C) 2004 Joe Walnes. | ||
* Copyright (C) 2006, 2007, 2013, 2014, 2018 XStream Committers. | ||
* Copyright (C) 2006, 2007, 2013, 2014, 2018, 2019 XStream Committers. | ||
* All rights reserved. | ||
* | ||
* The software in this package is published under the terms of the BSD | ||
* style license a copy of which has been included with this distribution in | ||
* the LICENSE.txt file. | ||
* | ||
* | ||
* Created on 29. May 2004 by Joe Walnes | ||
*/ | ||
package com.thoughtworks.xstream.converters.extended; | ||
|
||
import java.io.IOException; | ||
import java.io.ObjectInputStream; | ||
import java.io.Serializable; | ||
|
||
import com.thoughtworks.xstream.converters.Converter; | ||
import com.thoughtworks.xstream.converters.ConverterLookup; | ||
import com.thoughtworks.xstream.converters.MarshallingContext; | ||
import com.thoughtworks.xstream.converters.UnmarshallingContext; | ||
import com.thoughtworks.xstream.io.HierarchicalStreamReader; | ||
import com.thoughtworks.xstream.io.HierarchicalStreamWriter; | ||
import com.thoughtworks.xstream.mapper.Mapper; | ||
|
||
|
||
/** | ||
* Converter for {@link Throwable} (and {@link Exception}) that retains stack trace. | ||
* | ||
* | ||
* @author <a href="mailto:[email protected]">B. K. Oxley (binkley)</a> | ||
* @author Joe Walnes | ||
* @author Jörg Schaible | ||
*/ | ||
public class ThrowableConverter implements Converter { | ||
|
||
private Converter defaultConverter; | ||
private static final String ATTRIBUTE_SERIALIZATION = "serialization"; | ||
private final Converter defaultConverter; | ||
private final ConverterLookup lookup; | ||
private final Mapper mapper; | ||
|
||
/** | ||
* @deprecated As of 1.4.5 use {@link #ThrowableConverter(ConverterLookup)} | ||
|
@@ -38,13 +45,27 @@ public class ThrowableConverter implements Converter { | |
public ThrowableConverter(final Converter defaultConverter) { | ||
this.defaultConverter = defaultConverter; | ||
lookup = null; | ||
mapper = null; | ||
} | ||
|
||
/** | ||
* @since 1.4.5 | ||
* @deprecated As of upcoming use {@link #ThrowableConverter(Mapper, ConverterLookup)} | ||
*/ | ||
@Deprecated | ||
public ThrowableConverter(final ConverterLookup lookup) { | ||
this.lookup = lookup; | ||
mapper = null; | ||
defaultConverter = null; | ||
} | ||
|
||
/** | ||
* @since upcoming | ||
*/ | ||
public ThrowableConverter(final Mapper mapper, final ConverterLookup lookup) { | ||
this.mapper = mapper; | ||
this.lookup = lookup; | ||
defaultConverter = null; | ||
} | ||
|
||
@Override | ||
|
@@ -68,11 +89,33 @@ public void marshal(final Object source, final HierarchicalStreamWriter writer, | |
} | ||
|
||
private Converter getConverter() { | ||
return defaultConverter != null ? defaultConverter : lookup.lookupConverterForType(Ser.class); | ||
} | ||
|
||
private Converter getConverter14() { | ||
return defaultConverter != null ? defaultConverter : lookup.lookupConverterForType(Object.class); | ||
} | ||
|
||
@Override | ||
public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) { | ||
return getConverter().unmarshal(reader, context); | ||
final String attributeName = mapper != null | ||
? mapper.aliasForSystemAttribute(ATTRIBUTE_SERIALIZATION) | ||
: ATTRIBUTE_SERIALIZATION; | ||
final Converter converter = attributeName != null && reader.getAttribute(attributeName) == null | ||
? getConverter14() | ||
: getConverter(); | ||
return converter.unmarshal(reader, context); | ||
} | ||
|
||
private static class Ser implements Serializable { | ||
private static final long serialVersionUID = 20190506L; | ||
|
||
@SuppressWarnings("unused") | ||
public Ser() { | ||
} | ||
|
||
private void readObject(final ObjectInputStream in) throws ClassNotFoundException, IOException { | ||
in.defaultReadObject(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters