Issue when serializing custom collections with additional properties

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Karthik1979
    New Member
    • Feb 2008
    • 2

    Issue when serializing custom collections with additional properties

    I have a custom class inherited from List<T> collection. Along with the base class functionality, I have included my additional properties. When serializing, only the base class items are serialized not my additional properties.

    I have designed a business object collection like this and I have to pass it across the service layer. But in another end I’m getting partial data not all my information is getting de-serialized. Here is a sample scenario.

    public class Student
    {
    int mRollno;
    string mStudentName;

    public string StudentName
    {
    get
    {
    return mStudentName;
    }
    set
    {
    mStudentName = value;
    }
    }

    public int Rollno
    {
    get
    {
    return mRollno;
    }
    set
    {
    mRollno = value;
    }
    }
    }


    public class Students : List<Student>
    {
    string mSchoolName;

    public string SchoolName
    {
    get
    {
    return mSchoolName;
    }
    set
    {
    mSchoolName = value;
    }
    }
    }

    If I serialize this “Students” collection, I’m getting following XML, but it is missing the additional property SchoolName of Students.

    <?xml version="1.0"?>
    <ArrayOfStude nt xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http ://www.w3.org/2001/XMLSchema">
    <Student>
    <StudentName>On e</StudentName>
    <Rollno>1</Rollno>
    </Student>
    <Student>
    <StudentName>Tw o</StudentName>
    <Rollno>2</Rollno>
    </Student>
    <Student>
    <StudentName>Th ree</StudentName>
    <Rollno>3</Rollno>
    </Student>
    </ArrayOfStudent>

    Please guide me what I’m missing here. Thanks in advance.
  • Karthik1979
    New Member
    • Feb 2008
    • 2

    #2
    I have solved this by implementing IXMLSerialize interface.

    Comment

    Working...