Following on from #121 , it seems that IReadOnlyCollection is not currently supported, throwing an ArgumentNullException on serialisation. Changing from an IReadOnlyCollection to IEnumerable works.
IReadOnlyCollection seems a better fit for immutable objects.
[TestMethod]
public void HandlesReadOnlyCollection()
{
var entity = new Entity { Items = new[] { "One", "Two", "Three" } };
var serialised = NetJSON.NetJSON.Serialize(entity, Settings);
var deserialised = NetJSON.NetJSON.Deserialize<Entity>(serialised, Settings);
Assert.AreEqual(entity.Items.Count(), deserialised.Items.Count());
foreach (var item in entity.Items)
Assert.IsTrue(deserialised.Items.Contains(item));
}
public class Entity
{
public IReadOnlyCollection<string> Items { get; set; }
}
Following on from #121 , it seems that IReadOnlyCollection is not currently supported, throwing an ArgumentNullException on serialisation. Changing from an IReadOnlyCollection to IEnumerable works.
IReadOnlyCollection seems a better fit for immutable objects.