Open hardcodet opened 7 years ago
List instantiation handling:
Alternatively you can update ContructorDelegateFactory to check whether the type is an IList:
internal virtual ReflectionUtils.ConstructorDelegate ContructorDelegateFactory(Type key)
{
bool isArray = key.IsArray || typeof(IList).IsAssignableFrom(key);
return ReflectionUtils.GetContructor(key, isArray ? ArrayConstructorParameterTypes : EmptyTypes);
}
Since the lib doesn't seem to be supported anymore, here's a few fixes and workarounds I added to get me going to deserialize some simple DTOs that were created through Json.net:
DateTime/DateTimeOffset parsing
The format used by Json.net caused me exceptions when trying to deserialize them. I replaced the DateTime/DateTimeOffset parsing as follows, which makes Json.net's IsoDateTimeConverter:
Enum deserialization
In DeserializeObject, I added this (before the string evaluation):
List instantiation handling
That looked like a bug and crashed on me at runtime. The parser seems to try and create lists with a capacity parameter, but it appears that at runtime, the wrong constructor is invoked, me a
TargetParameterCountException
. InDeserializeObject
, find the line where the lists are being created and just remove the constructor parameter like so:Then make sure the constructor cache works without parameters by adjusting this method and removing the distinction between arrays and other types: