13
Ok, we're using Newtonsoft's JSON.NET product, which I really love. However, I have a simple class structure for hierarchical locations that look roughly like this...
public class Location {
public string Name { get; set; }
public LocationList Locations { get; set; }
}
// Note: LocationList is simply a subclass of a List<T>
// which then adds an IsExpanded property for use by the UI.
public class LocationList : List<Location> {
public bool IsExpanded { get; set; }
}
public class RootViewModel {
public LocationList RootLocations{ get; set; }
}
...and when I serialize them to JSON, it all works great, except the IsExpanded property on the LocationList class is excluded. Only the list's contents are serialized.
Now here's what I'm envisioning would be a good format. It's esentially the same thing as if LocationList wasn't a subclass of List<Location> but rather was just a regular object that had a property called Items of type List<Location> instead.
{
"Locations" : {
"IsExpanded" : true,
"Items" : [
{
"Name" : "Main Residence",
"Locations" : {
"IsExpanded" : true,
"Items" : [
{
"Name" : "First Floor",
"Locations" : {
"IsExpanded" : false,
"Items" : [
{
"Name" : "Livingroom"
},
{
"Name" : "Dining Room"
},
{
"Name" : "Kitchen"
}
]
}