Using JsonProperty with RestSharp

1,569 views
Skip to first unread message

Nils-Helge Garli Hegvik

unread,
Mar 21, 2013, 7:20:56 AM3/21/13
to rest...@googlegroups.com
I'm trying to customize JSON serialization using RestSharp and got a suggestion to use the JsonProperty attribute, which I believe is a Newtonsoft.Json attribute. What I'm trying:

public class MyClass {
    
    [JsonProperty("myField")]
    public string MyField {get;set;}

    [JsonProperty("myOtherField")]
    public string MyOtherField {get;set;}

}

When the object is serialised, the resulting JSON is

{"MyField": "fieldvalue", "MyOtherField": "otherfieldvalue"} rather than what I want, which is: {"myField": "fieldvalue", "myOtherField": "otherfieldvalue"}

So it seems that RestSharp is ignoring the JsonProperty attributes I'm specifying.

I'm using RestSharp for MonoTouch, and I have added Newtonsoft.Json.MonoTouch as a reference in the project.

Andrew Young

unread,
Mar 22, 2013, 12:53:26 PM3/22/13
to rest...@googlegroups.com
JsonProperty is specific to json.net. If you want that support you'll need to implement your own ISerializer and have json.net serialize it for you vs. the default serializer in RestSharp.

Andrew Young

--
Sent with Sparrow

--
You received this message because you are subscribed to the Google Groups "RestSharp" group.
To unsubscribe from this group and stop receiving emails from it, send an email to restsharp+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Reply all
Reply to author
Forward
0 new messages