[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""}"));
}
}
le nom de propriété fonctionne mais le type de couverture d'élément ne fonctionne pas
j'utilise la propriété wring,
[JsonConverter(typeof(StringEnumConverter))]
Fonctionne bien.
6 ans plus tard et la documentation m'a toujours induit en erreur pour faire cette erreur.
Commentaire le plus utile
j'utilise la propriété wring,
Fonctionne bien.