c# - Custom JsonConverter is ignored for DEserialization when using custom contract resolver instead of JsonConverter attribute -


I Jason for serialization I am using Net (6.0.3). I custom JsonConverter TestConverter wrote that handles some instances BaseClass (by converting them into an integer ID and back). Everything is working fine when I interpret the properties in my classes with JsonConverter [typeof (TestConverter)] .

I'm still as much rather prefer to use a custom contract resolver, which should fully be able to change to use all features

Here's how I established the contract resolver:

  Protected Override JsonProperty CreateProperty (MemberInfo Member, MemberSerialization Subscribing) {var Properties = Base. CreteProperty (Member, Member Empowerment); If (type class). ISSA SignableForm (property type)) {property.Converter = New TestConverter (); } Return Property; }   

Everything is working fine for serialization, but it seems that the converter I have been established in the contract resolver is not focus entirely on The given amount is done during the process. ReadJson the method TestConverter is never called

Am I really forgetting something? Do I have to attach the property converter to some other place?

I have since commented on a small built Rnniy example demonstrates the problem if [JsonConverter] line featuring 57, will crash with an exception for this program Json.net is trying to convert an object to an integer instead of using the TestConverter . For example, the source can be found here:

Thanks in advance for any help!

[JsonConverter (typeof (TestConverter))] artist attribute code Remove song class. The following sample contract resolver setup changes to:

  public class TestContractResolver: DefaultContractResolver {protected override JsonProperty CreateProperty (MemberInfo member, MemberSerialization memberSerialization) {var property = base.CreateProperty (member, memberSerialization) ; If (base class) .asassngablefom (property type type)) {var converter = new testconter (); Property. Converter = converter; Property.MemberConverter = converter; } Return Property; }}   

Everything should work fine.

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -