Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JsonProperty.ItemConverterType does not work when decorated on base class #57

Closed
steveoh opened this issue Feb 21, 2013 · 3 comments
Closed

Comments

@steveoh
Copy link

steveoh commented Feb 21, 2013

[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""}"));
    }
}
@steveoh
Copy link
Author

steveoh commented Feb 21, 2013

the propertyname works but the itemcovertertype does not

@steveoh
Copy link
Author

steveoh commented Feb 22, 2013

i'm using the wring property,

    [JsonConverter(typeof(StringEnumConverter))]

Works fine.

@steveoh steveoh closed this as completed Feb 22, 2013
@mark-branchboston
Copy link

6 years later and the documentation still misled me to make this mistake.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants