Issue in implementing CustomNamingPolicy for Deserializing Json RRS feed

  • Question

  • Hi,
    I am using System.Text.Json for Deserializing.

    I have a class "TransactionResponse" with two properties
         public List<TransactionDetails> TransactionDetails { get; set; }
         public Page PageInfo { get; set; }

    Now I am trying to Deserialize the above class and using CustomJsonNamingPolicy as below:

    public override string ConvertName(string name)
                if (name == null)
                    throw new ArgumentNullException(nameof(name));
                    return $"m_{name}";
    I am converting to m_<PropertyName> because in my datacontract the datamember starts with m_ and my json also returns properties with m_.
    For Deserializing,

     var serializeOptions = new JsonSerializerOptions
                    PropertyNamingPolicy = new CustomJsonNamingPolicy(),
                    WriteIndented = true,
    var f =  JsonSerializer.Deserialize<TransactionResponse>(result,serializeOptions);

    But in CustomJsonNamingPolicy the property name comes to be names of class "TransactionResponse" and not the actual properties present in "TansactionDetails".

    Am I missing something? Please help.


    Monday, March 30, 2020 1:16 PM