Re: [Simple-support] deserializing inheritance in differently shaped XML
Brought to you by:
niallg
|
From: Christian P. <Chr...@ca...> - 2012-03-21 08:58:19
|
Hi,
thanks for the quick response! The constructor should not be the source of the problem, as first, "Widget" is an abstract class, and second, when I serialized the class structure with simple, the deserialization worked fine. I now wonder, is there a way to make simple realize that <widgets xsi:type="thisModel:Button" name="btn1"/> means that a subclass of widget, a button, needs to be created? Or is the only solution to make the abstract class concrete and give it an attribute named "type"?
The stack trace:
org.simpleframework.xml.core.InstantiationException: Cannot instantiate class thismodel.Widget for class thismodel.Widget
at org.simpleframework.xml.core.ObjectFactory.getInstance(ObjectFactory.java:68)
at org.simpleframework.xml.core.Composite.read(Composite.java:141)
at org.simpleframework.xml.core.Traverser.read(Traverser.java:92)
at org.simpleframework.xml.core.CompositeInlineList.read(CompositeInlineList.java:190)
at org.simpleframework.xml.core.CompositeInlineList.read(CompositeInlineList.java:167)
at org.simpleframework.xml.core.CompositeInlineList.read(CompositeInlineList.java:124)
at org.simpleframework.xml.core.Composite.readVariable(Composite.java:687)
at org.simpleframework.xml.core.Composite.readInstance(Composite.java:635)
at org.simpleframework.xml.core.Composite.readUnion(Composite.java:610)
at org.simpleframework.xml.core.Composite.readElement(Composite.java:593)
at org.simpleframework.xml.core.Composite.readElements(Composite.java:506)
at org.simpleframework.xml.core.Composite.readSection(Composite.java:388)
at org.simpleframework.xml.core.Composite.read(Composite.java:367)
at org.simpleframework.xml.core.Composite.readDefault(Composite.java:262)
at org.simpleframework.xml.core.Composite.read(Composite.java:232)
at org.simpleframework.xml.core.Composite.read(Composite.java:202)
at org.simpleframework.xml.core.Composite.read(Composite.java:150)
at org.simpleframework.xml.core.Traverser.read(Traverser.java:92)
at org.simpleframework.xml.core.CompositeInlineList.read(CompositeInlineList.java:190)
at org.simpleframework.xml.core.CompositeInlineList.read(CompositeInlineList.java:167)
at org.simpleframework.xml.core.CompositeInlineList.read(CompositeInlineList.java:124)
at org.simpleframework.xml.core.Composite.readVariable(Composite.java:687)
at org.simpleframework.xml.core.Composite.readInstance(Composite.java:635)
at org.simpleframework.xml.core.Composite.readUnion(Composite.java:610)
at org.simpleframework.xml.core.Composite.readElement(Composite.java:593)
at org.simpleframework.xml.core.Composite.readElements(Composite.java:506)
at org.simpleframework.xml.core.Composite.readSection(Composite.java:388)
at org.simpleframework.xml.core.Composite.read(Composite.java:367)
at org.simpleframework.xml.core.Composite.read(Composite.java:234)
at org.simpleframework.xml.core.Composite.read(Composite.java:202)
at org.simpleframework.xml.core.Composite.read(Composite.java:150)
at org.simpleframework.xml.core.Traverser.read(Traverser.java:92)
at org.simpleframework.xml.core.Persister.read(Persister.java:632)
at org.simpleframework.xml.core.Persister.read(Persister.java:613)
at org.simpleframework.xml.core.Persister.read(Persister.java:591)
at org.simpleframework.xml.core.Persister.read(Persister.java:550)
at org.simpleframework.xml.core.Persister.read(Persister.java:528)
at org.simpleframework.xml.core.Persister.read(Persister.java:433)
at test.deserialise(test.java:29)
at test.main(test.java:16)
Exception in thread "main" java.lang.NullPointerException
at test.main(test.java:17)
Thanks so much.
Christian
Von: Niall Gallagher [mailto:gal...@ya...]
Gesendet: Mittwoch, 21. März 2012 04:23
An: sim...@li...; Christian Paul
Betreff: Re: [Simple-support] deserializing inheritance in differently shaped XML
Hi,
Can u provide the stack trace? Also, has the class got a no argument constructor?
Niall
--- On Tue, 20/3/12, Christian Paul <Chr...@ca...> wrote:
From: Christian Paul <Chr...@ca...>
Subject: [Simple-support] deserializing inheritance in differently shaped XML
To: sim...@li...
Received: Tuesday, 20 March, 2012, 10:53 AM
Hello,
I'm using simple and I want to parse an xml file that looks something like this:
..
<pages name="page1">
<widgets xsi:type="thisModel:Button" name="btn1"/>
</pages>
..
"Button" subclasses the abstract "Widget".
My problem is: how can I make simple understand that? Serialized with Simple itself it would probably be sth. like: <widgets class="thisModel:Button" name="btn1" > .
But in the presented way, I get the error: "Cannot instantiate class thisModel.Widget for class thisModel.Widget".
What can I do? I'm really thankful for every hint.
Christian
-----Inline Attachment Follows-----
------------------------------------------------------------------------------
This SF email is sponsosred by:
Try Windows Azure free for 90 days Click Here
http://p.sf.net/sfu/sfd2d-msazure
-----Inline Attachment Follows-----
_______________________________________________
Simple-support mailing list
Sim...@li...
https://lists.sourceforge.net/lists/listinfo/simple-support
|