Re: [Simple-support] deserializing a list of subclasses
Brought to you by:
niallg
|
From: Niall G. <gal...@ya...> - 2008-12-26 12:49:13
|
Hi, Yes this is possible, this and other strategy based questions are probably the most common questions asked. So, I will make sure there are several new entries in the tutorial to describe how to use them. For now there is a good example in the following test case. http://simple.svn.sourceforge.net/viewvc/simple/trunk/download/stream/src/test/java/org/simpleframework/xml/core/InterceptorTest.java?revision=1128&view=markup Here you would change the logic slightly to ensure that serialization does not include the class attribute and that deserialization maps the element name to the class. Hope this helps, Niall --- On Wed, 12/24/08, Carl H. Sayres <ca...@da...> wrote: > From: Carl H. Sayres <ca...@da...> > Subject: [Simple-support] deserializing a list of subclasses > To: sim...@li... > Date: Wednesday, December 24, 2008, 2:38 AM > Is it possible to specify how elements map to classes in the > java code, > rather than in the xml using the class attribute? > Here's an example of > what I mean: > > Suppose I have classes as follows: > > package a.b.c.d; > class Component {} > class TextField extends Component {} > class TextArea extends Component {} > class Choice extends Component {} > > Using Simple, I can deserialize the following XML easily: > > <ComponentList> > <Component class="a.b.c.d.TextField" /> > <Component class="a.b.c.d.TextArea" /> > <Component class="a.b.c.d.Choice" /> > </ComponentList> > > I would like to be able to use the following instead: > > <ComponentList> > <TextField" /> > <TextArea" /> > <Choice" /> > </ComponentList> > > and specify how TextField, etc.. maps to an > a.b.c.d.TextField in the java > code. (Perhaps using some kind of Strategy?) > > Is this possible? > > Thanks, > > Carl > > > > > ------------------------------------------------------------------------------ > _______________________________________________ > Simple-support mailing list > Sim...@li... > https://lists.sourceforge.net/lists/listinfo/simple-support |