Jorg: Thanks for replying back to me. The problem I have is that the client that is constructing the XML is generating the XML without the "class" hints you have outlined in your example (so information about what concrete class is embedded in the xml is not present). Hope that clarifies the problem I am trying to see if there is a solution for?
Venkatesh On Thu, Jun 6, 2013 at 1:15 AM, Jörg Schaible <[email protected]>wrote: > Hi Venkatesh, > > Venkatesh wrote: > > > I have run into a problem using XStream to serialize and deserialize XML > > streams. The following is my scenario: > > > > public interface MyInterface { > > > > } > > > > public class MyObjectA implements MyInterface { > > private int x; .. > > } > > > > public class MyObjectB implements MyInterface { > > > > private String test; ... > > > > } > > > > public class ClassThatNeedsTransformation { > > private MyInterface x; > > } > > > > While XStream is able to serialize the ClassThatNeedsTransformation based > > on the type of object that is held by it, I am having problems getting > > XStream to deserialize the same based on the specific type held in "x". I > > read up some docs and it seems to indicate that I need to provide XStream > > with a "default" implementation class for the interface in which case, I > > lose the flexibility to store either of the concrete implementations of > > the interface. Wanted to know if this is indeed a limitation of XStream > > and if no, how I would overcome the same. Appreciate your help on the > > topic. > > I am not sure if I understand your problem correctly. Let's have a list > with > two instances of ClassThatNeedsTransformation, each one with a different > implementation for MyInterface. The resulting XML will look similar to: > > =========== %< ============== > <list> > <ClassThatNeedsTransformation> > <x class="MyObjectA"> > <x>42</x> > </x> > </ClassThatNeedsTransformation> > <ClassThatNeedsTransformation> > <x class="MyObjectB"> > <test>Arthur</test> > </x> > </ClassThatNeedsTransformation> > </list> > =========== %< ============== > > You see, the XML contains any information required to recreate the > persisted > object graph, the information which implementation has to be taken for the > MyInterface instance is kept in the "class" attribute. > > So, what do you want to do? > > Cheers, > Jörg > > > --------------------------------------------------------------------- > To unsubscribe from this list, please visit: > > http://xircles.codehaus.org/manage_email > > >
