I've got some business objects below that I can serialize and deserialize successfully with Json.NET. I don't see a simple way to do this with Esri's SOESupport however. I'm happy with Json.NET, but I'd like to leverage Esri's IGeometry conversion routines. Is there some way to get SOESupport to work for this?
Update:
Since it doesn't look like Esri can do this, I'm trying to use Json.NET. See my related issue on stackoverflow:
How can I deserialize with TypeNameHandling.Objects in Json.NET Silverlight?
public class Animal
{
public string Name { get; set; }
}
public class Dog: Animal
{
public bool LikesBones { get; set; }
}
public class Cat: Animal
{
public bool LikesMice { get; set; }
}
public class Zoo
{
public int ID { get; set; }
private List<Animal> m_Animals = new List<Animal>();
public List<Animal> Animals { get { return m_Animals; } set { m_Animals = value; } }
}
Is there some way to get Esri's JsonObject to support this sort of test?
public static void Test1()
{
// use Json.NET
Zoo z1 = new Zoo() { ID = 1 };
z1.Animals.Add(new Dog() { Name = "Fido", LikesBones = true });
z1.Animals.Add(new Cat() { Name = "Felix", LikesMice = false });
string s1 = Util.Serialize(z1);
Debug.Print(s1);
var z2 = Util.Deserialize<Zoo>(s1);
string s2 = Util.Serialize(z2);
Debug.Print(s2);
if (s1 != s2)
Debug.Print("failed");
else
Debug.Print("ok");
}
I can apply settings in Json.NET that force the typename to be serialized, allowing polymorphism for the list of Animals. How can I implement these same functions with SOESupport?
public static string Serialize(object o)
{
JsonSerializerSettings settings = new JsonSerializerSettings();
settings.TypeNameHandling = TypeNameHandling.Objects;
return JsonConvert.SerializeObject(o, Formatting.Indented, settings);
}
public static T Deserialize<T>(string s)
{
JsonSerializerSettings settings = new JsonSerializerSettings();
settings.TypeNameHandling = TypeNameHandling.Objects;
return JsonConvert.DeserializeObject<T>(s,settings);
}