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 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: 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. 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 Thanks in advance for any help! Everything should work fine. 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)] .
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; }
ReadJson the method
TestConverter is never called
[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:
[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; }}
Comments
Post a Comment