2

I am converting some logic from Newtonsoft and found one of following implementation

 public class CustomDataContractResolver : DefaultContractResolver
    {
        public Dictionary<string, string> FieldNameChanges { get; set; }
        public List<FieldValueReplica> FieldValueReplica { get; set; }

        protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization)
        {
            var property = base.CreateProperty(member, memberSerialization);
            if (property.DeclaringType != typeof(logEvent)) return property;

            if (FieldNameChanges.Count > 0 && FieldNameChanges.TryGetValue(property.PropertyName, out var newValue))
                property.PropertyName = newValue;
            
            return property;
        }
   }

Any one have converted DefaultContractResolver to System.Text.Json

Kamran Shahid
  • 3,616
  • 3
  • 39
  • 83
  • There is none that is public. See: [System.Text.Json API is there something like IContractResolver](https://stackoverflow.com/q/58926112/3744182). – dbc Nov 07 '20 at 15:42
  • :( Thanks dbc. Then could anyone help in above logic conversion to System.Text.Json – Kamran Shahid Nov 07 '20 at 16:02
  • You would need to create a custom [`JsonConverter`](https://docs.microsoft.com/en-us/dotnet/standard/serialization/system-text-json-converters-how-to) for `logEvent`. Alternatively, the linked question has an answer that suggests some third party extension that might do the job, but I haven't tried it so I can't say one way or the other. – dbc Nov 07 '20 at 16:16
  • no problem dbc. i am checking that link. may be some other guy have done similar and help in it – Kamran Shahid Nov 07 '20 at 20:00

0 Answers0