[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์ ์๋ํ์ง ์์ต๋๋ค.
๋๋ wring ์์ฑ์ ์ฌ์ฉํ๊ณ ์์ต๋๋ค.
[JsonConverter(typeof(StringEnumConverter))]
์ ์๋ํฉ๋๋ค.
6๋ ์ด ์ง๋ ํ์๋ ๋ฌธ์๋ ์ฌ์ ํ ๋๋ฅผ ์ด ์ค์๋ก ์ค๋ํ์ต๋๋ค.
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
๋๋ wring ์์ฑ์ ์ฌ์ฉํ๊ณ ์์ต๋๋ค.
์ ์๋ํฉ๋๋ค.