NancyFx / Nancy.Serialization.JsonNet

NewtonSoft.Json serializer for Nancy
MIT License
40 stars 32 forks source link

Updated JsonNetBodyDeserializer.cs to support array types #69

Open logiclrd opened 6 years ago

logiclrd commented 6 years ago

After encountering errors doing model binding to array types, I investigated the root cause and decided to fix it. It looks like JsonNetBodyDeserializer.cs creates a separate instance of the target type from that created during deserialization, and then manually copies properties over in order to support blacklisting of properties (a Nancy feature not directly integrated with Newtonsoft.Json). As part of this, JsonNetBodyDeserializer.cs assumes that it can use Activator.CreateInstance on the destination type. This does not work for arrays, as they do not have a parameterless constructor. The approach I took, since the deserialization is going to require the use of a List<T> anyway, is to leverage the existing List<T> deserialization, and then if the destination type is actually T[], call List<T>'s ToArray method before returning the final value.

Prerequisites

Description

logiclrd commented 6 years ago

So... I did fill in the CLA, I thought @dnfclas was supposed to replace the cla-required label with cla-signed? I went through the "working on behalf of my employer" flow, though, so maybe that requires manual attention...

MichaelTsengLZ commented 6 years ago

All CLA requirements met now. Check out the statuses. We are currently migrating to new CLA system which uses status instead of labels. :) image

logiclrd commented 6 years ago

Ahh, okay :-) Cool beans, then.

logiclrd commented 5 years ago

Ping!