Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

uppercase/lowercase keys in the serialized JSON #358

Closed
nilsga opened this issue Mar 21, 2013 · 5 comments
Closed

uppercase/lowercase keys in the serialized JSON #358

nilsga opened this issue Mar 21, 2013 · 5 comments

Comments

@nilsga
Copy link

nilsga commented Mar 21, 2013

Given the class

public class MyClass {
    public string MyField {get;set;}
    public string MyOtherField {get;set;}
}

the generated JSON will be

{"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.

@pedrolamas
Copy link
Contributor

Use JsonPropertyattribute 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;}
}

@nilsga
Copy link
Author

nilsga commented Mar 21, 2013

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.

@nilsga
Copy link
Author

nilsga commented Mar 26, 2013

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.

@elvisestevan
Copy link

It was opened a feature-request?

@hallem
Copy link
Member

hallem commented May 20, 2015

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants