0
我有以下設置:與JsonIgnore摘要屬性被序列化(Json.NET)
public abstract class A
{
[JsonIgnore]
public abstract Type Foo { get; }
}
public abstract class B : A
{
public override Type Foo { get { return typeof(D); } }
}
public class C : B
{
}
public abstract class D
{
}
我的問題是,當我通過以下序列C的實例:
JsonConvert.SerializeObject(instanceOfC, serializationSettings));
生成的JSON包含屬性Foo的條目。這是預期的結果嗎?
我serializationSettings
如下:
JsonSerializerSettings _serializationSettings = new JsonSerializerSettings
{
PreserveReferencesHandling = PreserveReferencesHandling.Objects,
ReferenceLoopHandling = ReferenceLoopHandling.Serialize,
TypeNameHandling = TypeNameHandling.All,
ConstructorHandling = ConstructorHandling.AllowNonPublicDefaultConstructor
};
編輯:使用Json.NET 6.0.0和.NET 4.5。
我不能和你給的代碼重現此問題。請參閱https://dotnetfiddle.net/aEUy3p – 2015-02-11 15:09:07