kevin-montrose / Jil

Fast .NET JSON (De)Serializer, Built On Sigil
MIT License
2.15k stars 253 forks source link

Fails to deserialize List<T> when T[] succeeds #332

Open kstreichergb opened 5 years ago

kstreichergb commented 5 years ago
[
    {
        "id": "5d88c128ca43bc00084b60b2",
        "entityId": "68581f16-18c7-4dbf-93dd-237c291a085c"
    }
]

Cannot be deserialized into

    public class MatchingResultDto
    {
        [DataMember(Name = "id")] public string Id { get; set; }
        [DataMember(Name = "entityId")] public Guid EntityId { get; set; }
    }

Deserialization throws Unexpected ]

using (var input = new StringReader(result))
                {
                    var deserializedArray = JSON.Deserialize<MatchingResultDto[]>(input, jilOptions);
                    var deserializedList = JSON.Deserialize<List<MatchingResultDto>>(input, jilOptions); // This fails
                    var results = deserializedArray?.ToList() ?? new List<MatchingResultDto>();
                }

But Array serialization works.