0

A guy at work used:

var s = new JsonSerializerSettings();
s.ContractResolver = new CamelCasePropertyNamesContractResolver();

To create some JSON, but now I have to deserialize into objects that do not use camel case, without use annotations in the (shared) models. Models do not use camel case.

He uses Javascript, so no big deal for him, but I am in C# land.

Is there a "reverse" for CamelCasePropertyNamesContractResolver? I don't see a way to do this without annotations.

Gerry
  • 1,031
  • 1
  • 14
  • 30
  • 1
    If you are using Json.NET to deserialize, then it should just work, because Json.NET's deserialization code does a case-insensitive match of JSON property name to c# property name. Do you actually have a case that does not work? Can you expand your question into a [mcve]? – dbc Jan 26 '17 at 22:16
  • 1
    It should work automatically whereas if not you also use property attribute like [`JsonProperty`](http://www.newtonsoft.com/json/help/html/T_Newtonsoft_Json_Serialization_JsonProperty.htm) – Mohit S Jan 27 '17 at 09:58

1 Answers1

1

Input Json looks like "dataScope": { "type": 4, "clientId": 2, "areaId": 1, "areaName": "Simulator Area", "unitId": 1, "unitName": "Sim-A0B0", "wheelPosition": 1 }, etc, etc.

Target object like:

public class DataScope
{
    public int Type { get; set; }
    public int ClientId { get; set; }
    public string ClientName { get; set; }
    etc

Mohit is right, it is case insensitive. Problem turned out to be I forgot the public quantifier on my members.

Gerry
  • 1,031
  • 1
  • 14
  • 30