rpgmaker / NetJSON

Faster than Any Binary? Benchmark: http://theburningmonk.com/2014/08/json-serializers-benchmarks-updated-2/
MIT License
225 stars 29 forks source link

IReadOnlyCollection Support #205

Closed ghost closed 5 years ago

ghost commented 5 years ago

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; }
}
rpgmaker commented 5 years ago

Thanks. Will look into it.

rpgmaker commented 5 years ago

It is supported now. I will create a new nuget package once i fix the other two issues. Thanks

rpgmaker commented 5 years ago

It is published on nuget and should be available soon.

ghost commented 5 years ago

Tested and working, thanks!