Reputation: 520
In using json.net I'm required to adjust the (de)serializer settings, so I create a JsonSerializerSettings
instance and use it like this:
JsonConvert.DeserializeObject<SomeType>(someString, mySerializerSettings.ss);
But I then find it necessary to use a custom JsonConverter
for some banged up data, and then use it like this:
JsonConvert.DeserializeObject<SomeType>(someString, new myConverter());
But I'm now finding I need to use both JsonSerializerSettings
and a custom converter but I don't see any overloads of the DeserializeObject
method that would allow that.
What might I be missing?
I'm using .net v4.5.2 and json.net v10.0.
Upvotes: 4
Views: 3979
Reputation: 129667
JsonSerializerSettings
has a Converters
collection. So add your converter to that collection and then pass the settings to DeserializeObject
.
mySerializerSettings.ss.Converters.Add(new myConverter());
var obj = JsonConvert.DeserializeObject<SomeType>(someString, mySerializerSettings.ss);
Upvotes: 9