Serialize full object graph

Jan 26, 2009 at 2:13 PM
I have an object say for example:

class Person {
        public string Name { get; set; }
        public int Age { get; set; }
        public Address Address { get; set; }
}

class Address {
        public string HouseNo{ get; set; }
        public string Street { get; set; }
        public string Town { get; set; }
}

I want to pass this to my UI layer as json in order to populate. When I run JavaScriptConvert.SerializeObject(new Person()) I only get the following:
function Person() {
    this.Name = null;
    this.Age= null;
    this.Address = null; 
}

Instead I need the full object graph:
function Person() {
    this.Name = null;
    this.Age= null;
    this.Address = function() {
             this.HouseNo = null;
             this.Street = null;
             this.Town = null;
    };
}

Is there any way to do this?

Thanks
Coordinator
Jan 28, 2009 at 5:58 AM
Assign a blank Address to the person object before you serialize?