Cannot deserialize list of nested objects

Apr 21, 2011 at 8:14 PM

I have a list of viewmappingobjects that i serialize where each item may have a collection of sendermappingitems within them

The nested class is defined as a generic list of  <sendermappingitem>

The serialization works well as shown below , bet when i deserialize i get back a zero instanses.

Am i missing something. ?

<ViewMappingItem>
  <BoundViewID>17</BoundViewID>
  <ReceiverName>dsa</ReceiverName>
  <ReceiverID>31</ReceiverID>
  <SenderMappingItems>
    <SenderMappingItem>
      <SenderBoundProperty>asdas</SenderBoundProperty>
      <SenderObjectID>31</SenderObjectID>
      <SenderType>SearchVariant_UI</SenderType>
      <ReceiverBoundProperty>dasd</ReceiverBoundProperty>
    </SenderMappingItem>
  </SenderMappingItems>
</ViewMappingItem>

PS If i do not added any items in the child collection the deserialization works correct .

Problem occurs if i add a  <SenderMappingItem> to the child collection

ViewMappingItem.SenderMappingItems.add(SenderMappingItem)

 

Coordinator
Apr 23, 2011 at 9:16 AM

I created a sample class like what you already have and everything was OK. Could you please tell me what version of YAXLib you are using. Please make sure you are using the latest version downloaded from the source repository: http://yaxlib.codeplex.com/SourceControl/list/changesets

Can you also verify that the following sample class that I created is like your own classes? If not could you please your ViewMappingItem and SenderMappingItem class definitions?

    public class FreeSample
    {
        public int BoundViewID { get; set; }
        public List<SenderMappingItem> SenderMappingItems { get; set; }

        public static FreeSample GetSampleInstance()
        {
            var lstMappings = new List<SenderMappingItem>();
            lstMappings.Add(new SenderMappingItem()
                                {
                                    SenderBoundProperty = "asdas",
                                    SenderObjectID = 31,
                                    SenderType = "SearchVariant_UI",
                                    ReceiverBoundProperty = "dasd"
                                }
                );

            return new FreeSample
                       {
                           BoundViewID = 17,
                           SenderMappingItems = lstMappings
                       };
        }


        public override string ToString()
        {
            return GeneralToStringProvider.GeneralToString(this);
        }

    }

    public class SenderMappingItem
    {
        public string SenderBoundProperty { get; set; }
        public int SenderObjectID { get; set; }
        public string SenderType { get; set; }
        public string ReceiverBoundProperty { get; set; }

    }

Apr 28, 2011 at 2:37 PM

thank you for your response.

actually i figured it out. 

The problem was that i was not serializing a class with a single root or top level node.

so i was trying to serialize a list of viewmapping items , where the collection was the root node.

Once i encapsulated the collection under as a child of a root level class and serialized that class than all child nodes serialized/deserialized correctly.

Thanks again.

Giannis

 

Coordinator
Apr 29, 2011 at 8:14 AM

You're welcome. I'm glad that your problem is solved.

Sina