Given the class
``` c#
public class MyClass {
public string MyField {get;set;}
public string MyOtherField {get;set;}
}
the generated JSON will be
``` javascript
{"MyField": "field value", "MyOtherField": "other field value"}
However, the REST API on the other end of the wire follows another naming convention where the keys are expected to be in lowercase, like
{"myField": "field value", "myOtherField": "other field value"}
Is there an easy way to achieve this without resorting to a custom serializer? It's such a small change that preferrably it would only be a configuration switch somewhere.
Use JsonProperty
attribute on the property to specify a different name when serialized!
public class MyClass {
public string MyField {get;set;}
[JsonProperty("myOtherField")]
public string MyOtherField {get;set;}
}
Sounds like what I need, but I can't find this attribute in RestSharp. Do I need to import some other dll? I'm using the MonoTouch version of RestSharp.
Edit: I added the Newtonsoft.Json MonoTouch library and added the attribute, but it was still generating keys with uppercase letters.
I asked about this on the mailing list, and got a response that this is something specific to JSON.NET, not RestSharp. If that's the case, I would like to open this issue as a feature request.
It was opened a feature-request?
it was not. if this feature is needed then RestSharp gives you the ability to use a custom de/serializer so you'd have to use that for now.
Most helpful comment
Use
JsonProperty
attribute on the property to specify a different name when serialized!