我有一个简单的不可变 POCO 定义为:
public sealed class Person
{
public Person(string name)
{
Name = name;
TimeStamp = DateTimeOffset.UtcNow;
}
public DateTimeOffset TimeStamp { get; }
public string Name { get; }
}
然后我做一个简单的序列反序列化:
var p = new Person("Mr Right").Dump();
var ser = JSON.Serialize(p).Dump();
// Throws Deserialization Exception, Error occured building a deserializer,
// Expected a parameterless constructor...
JSON.Deserialize<Person>(ser).Dump();
序列化成功产生:
{"TimeStamp":"/Date(1456412550349+0000)/","Name":"Mr Right"}
但是反序列化抛出,知道如何解决它吗?是否JIL
支持使用参数化构造函数对类型进行反序列化?