Stephen Cossgrove
Stephen Cossgrove

Reputation: 161

NewtonSoft JsonConverter Constructor Parameter

I want to pass in a parameter to a Custom JsonConverter, Can anyone tell me how to do this?

public class MySerializer: JsonConverter
{
    private object _someObject;
    public MySerializer(object someObject)
    {
       _someObject = someObject;
    }
}

[JsonConverter(typeof(MySerializer))]
public class SomeClass
{        
}

The problem is that I'm setting the serializer as an attribute but need the converter to have the parameter.

Upvotes: 2

Views: 9418

Answers (1)

Codename
Codename

Reputation: 56

I believe that one solution could be:

[JsonConverter(typeof(MySerializer), new object())]
public class SomeClass
{

}

Upvotes: 4

Related Questions