1

We use

jsonFormatterSerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver() 

globally in our webapi project but for one particular Dictionary property I want to override this. This is because the strings which represent the keys in the Dictionary are having their cases transformed and I want to return the original unmodified values. I tried this setting but it didn't work the keys were still camel case.

[JsonProperty(NamingStrategyType = typeof(DefaultNamingStrategy)]      
public IDictionary<string, long?> Data { get; set; }
Mohammed Sajid
  • 4,778
  • 2
  • 15
  • 20
Pchard
  • 11
  • 1
  • Looks pretty much like a duplicate of [How to make Json Serialize ignore dictionary keys](https://stackoverflow.com/q/58501943/3744182). There the OP is trying to add `SnakeCaseNamingStrategy` to a dictionary property rather than `DefaultNamingStrategy` and is using global serializer settings rather than explicit settings - but the [answer](https://stackoverflow.com/a/58509729/3744182) is still the same. – dbc Jan 20 '21 at 19:25
  • Does that answer your question or do you need additional help? Applying `[JsonConverter(typeof(VerbatimDictionaryConverter))]` from [that answer](https://stackoverflow.com/a/58509729/3744182) to `Data` should work for you. – dbc Jan 20 '21 at 19:56
  • Excellent, thanks that really helps. – Pchard Jan 20 '21 at 20:01

0 Answers0