Re: [Simple-support] Asymmetry in Persister behaviour
Brought to you by:
niallg
|
From: Niall G. <gal...@ya...> - 2011-01-12 09:34:26
|
Hi, Take a look at the following, it works fine. https://simple.svn.sourceforge.net/svnroot/simple/trunk/download/stream/src/test/java/org/simpleframework/xml/convert/WrapperTest.java Niall --- On Tue, 11/1/11, Pete Calvert <pr...@ca...> wrote: > From: Pete Calvert <pr...@ca...> > Subject: [Simple-support] Asymmetry in Persister behaviour > To: sim...@li... > Received: Tuesday, 11 January, 2011, 4:25 PM > Hi, > > I've noticed that the behaviour of write(Object, > OutputNode) and > read(Class, InputNode) is not entirely consistent. read > loads directly > from the node whereas write first creates a new child > (using the name of > the object's class) and then writes to this. > > Is there a way of working around this? i.e. write writing > directly to > the node given? > > The reason I need this is that I'm trying to import/export > Objectify > entities. References to other entities are stored as > "Key<T>", so I've > got a Converter for "Key" that 'skips' over the reference > to export the > entity in its place. I've included some code at the end of > the email > that exhibits the behaviour I'm talking about. > > Thanks > Pete > > --- > > import org.simpleframework.xml.*; > import org.simpleframework.xml.strategy.*; > import org.simpleframework.xml.convert.*; > import org.simpleframework.xml.core.*; > import org.simpleframework.xml.stream.*; > import java.io.*; > > public class Test { > @Root > public static class Example { > @Element Foo x; > } > > public static class Foo { > String val; > > public Foo(String x) { val = x; } > } > > public static class FooConverter > implements Converter<Foo> { > public Foo read(InputNode node) > throws Exception { > return new Foo(new > Persister().read(String.class, node)); > } > > public void write(OutputNode node, > Foo f) throws Exception { > new > Persister().write(f.val, node); > } > } > > public static void main(String[] args) > throws Exception { > Registry registry = new > Registry(); > Strategy strategy = new > RegistryStrategy(registry); > Serializer serializer = new > Persister(strategy); > > registry.bind(Foo.class, > FooConverter.class); > > Example bla = new Example(); > bla.x = new Foo("test"); > > serializer.write(bla, new > File("example.xml")); > serializer.read(Example.class, new > File("example.xml")); > } > } > > ------------------------------------------------------------------------------ > Protect Your Site and Customers from Malware Attacks > Learn about various malware tactics and how to avoid them. > Understand > malware threats, the impact they can have on your business, > and how you > can protect your company and customers by using code > signing. > http://p.sf.net/sfu/oracle-sfdevnl > _______________________________________________ > Simple-support mailing list > Sim...@li... > https://lists.sourceforge.net/lists/listinfo/simple-support > |