[TestFixture]
public class JsonPropertyItemConverterType
{
public enum Thingy
{
Test
}
[JsonObject(MemberSerialization.OptIn)]
public abstract class Base
{
[JsonProperty(PropertyName = "type", Required = Required.Always, Order = 0,
ItemConverterType = typeof (StringEnumConverter))]
public Thingy Type { get; internal set; }
}
public class Thing : Base
{
public Thing()
{
Type = Thingy.Test;
}
}
[Test]
public void ItShouldWork()
{
var json = JsonConvert.SerializeObject(new Thing());
Assert.That(json, Is.EqualTo(@"{""type"":""Test""}"));
}
[Test]
public void ItShouldWork2()
{
var json = JsonConvert.SerializeObject(new Thing(), new StringEnumConverter());
Assert.That(json, Is.EqualTo(@"{""type"":""Test""}"));
}
}
propertynameは機能しますが、itemcovertertypeは機能しません
私は絞りプロパティを使用しています、
[JsonConverter(typeof(StringEnumConverter))]
正常に動作します。
6年後、ドキュメントはまだ私をこの間違いを犯すように誤解させました。
最も参考になるコメント
私は絞りプロパティを使用しています、
正常に動作します。