[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""}"));
}
}
el propertyname funciona pero el itemcovertertype no
estoy usando la propiedad wring,
[JsonConverter(typeof(StringEnumConverter))]
Funciona bien.
6 años después y la documentación todavía me engañaba para cometer este error.
Comentario más útil
estoy usando la propiedad wring,
Funciona bien.