This is a stretch, but it's a real world example, yet fluffified.. We have a Data node with multiple Fluff objects in a list. They are named according to their index in the list, as such: { Fluff_0, Fluff_1, ..., Fluff_n }
When I deserialize this object I would want it to be deserialized into a List<Fluff>.
Is there a way to decorate this with JsonPropertyAttributes so that I would get an ordered generic List (or other collection) of Fluff objects in the Data object?
[TestFixture]
public class FluffDeserializationTests
{
[Test]
public void FluffDeserialization()
{
var json = "{\"Data\": { \"Fluff_0\": {\"ID\": \"abc\"}, \"Fluff_1\": { \"ID\": \"abd\" } } }";
var result = JsonConvert.DeserializeObject<Fluff>(json);
Assert.That(result.Data.Things != null);
Assert.That(result.Data.Things.Count, Is.EqualTo(2));
Assert.That(result.Data.Things[0].ID, Is.EqualTo("abc"));
Assert.That(result.Data.Things[1].ID, Is.EqualTo("abd"));
}
public class Fluff
{
public Data Data { get; set; }
}
public class Data
{
public List<Thing> Things { get; set; }
}
public class Thing
{
public string ID { get; set; }
}
}
"Data"container is a JSON object, which the standard defines as an unordered set of name/value pairs. So, what order do you expect the list to be in after deserialization?