My favorites | Sign in
Project Home Downloads Wiki Issues Source
READ-ONLY: This project has been archived. For more information see this post.
Search
for
  Advanced search   Search tips   Subscriptions
Issue 60: Can I deserialize derived type object to baseclass property?
1 person starred this issue and may be notified of changes. Back to list
Status:  Fixed
Owner:  ----
Closed:  Apr 2012


 
Reported by s...@powtoon.com, Feb 22, 2012
What steps will reproduce the problem?
1. i have this situation:
   [XmlClass]
   class A{}

   [XmlClass]
   class B extends A{}
   
   [XmlClass]
   class X
   { 
      [XmlElement(alias="*")]
      public var a:A; 
   }
  
   x:X = new X();
   x.a = new B();
   
   serialize x gives me:
   <X>
      <B/>
   </X>

   now i deserialize this:

   var newX:X = deserialize(<X><B/></X>); 

   and now newX.a is null.

   is there a way to make this work so that newX.a will be assigned the B instance serialized before?



Feb 22, 2012
Project Member #1 alex.id....@gmail.com
Hmmm... i think this should have worked. I'll take a look and let you know.
Status: Accepted
Apr 14, 2012
Project Member #2 alex.id....@gmail.com
Well, this is the corner case which FlexXB can't handle by itself. The problem is that you define in X a field of type A to which you assign a derived b type value and FlexXB does not have a handle on that b tag. In your object you will probably have many fields and it will not be able to find the correct b field. What you can do is provide a virtual path to the a field and set getRuntimeType to true:

class X
{ 
   [XmlElement(alias="value/*", getRuntimeType="true")]
   public var a:A; 
}
Your XML will look like:
<X>
   <value>
      <B/>
   </value>
</X>

I found a problem preventing FlexXB from getting teh right value event in these conditions but that will be fixed shortly. Anyway, this is the way to go when dealing with derived types as there is no way of knowing if it's A or B or C there.
Status: Started
Apr 14, 2012
Project Member #3 alex.id....@gmail.com
(No comment was entered for this change.)
Labels: Milestone-2.3.1
Apr 14, 2012
Project Member #4 alex.id....@gmail.com
(No comment was entered for this change.)
Status: Fixed

Powered by Google Project Hosting