Details
-
Type: New Feature
-
Status: Open
-
Resolution: Unresolved
-
Affects Version/s: None
-
Fix Version/s: None
-
Component/s: None
-
Labels:None
Description
Here's a new feature I'd find useful...
When serializing an object graph, I'd like to specify certain objects (that may appear anywhere in the graph) that should be detached at serialization time (i.e not serialized) and then reattached at deserialization time.
Here's an example.
class Thing {
int id;
DataSource ds;
}
Thing t = new Thing();
t.id = 3;
t.ds = // lookup some heavyweight SQL DataSource from somewhere
// Serialization
XStream xstream = new XStream();
xstream.attach("myds", ds);
xstream.toXml(t)
// Produces...
<Thing>
<id>3</id>
<ds id="myds"/>
</Thing>
// Deserialization
XStream xstream = new XStream();
xstream.attach("myds", ds); // could be another datasource
xstream.fromXml(xml)
This is similar to an idea of definable default values:
xstream.setDefaultValue(Thing.class, "ds", ds);
If the default value matches the value, it is omitted from the stream (instead of the null values).