RestSharp: Dot in JSON property problem

Hi,

I’m having trouble with reading Json response that has dot in it’s property name.

I tried this

    [JsonProperty("ckan.locale_default")]
    [DeserializeAs(Name = "ckan.locale_default")]
    [SerializeAs(Name = "ckan.locale_default")]
    public string CkanLocaleDefault { get; set; }

but with no effect.

Is there any parser that forgot to add dot or something…

Tnx, Marko

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Reactions: 3
  • Comments: 16 (6 by maintainers)

Most upvoted comments

I just wanted to confirm that the 106.1.0 version fixes this issue for me, I had previously tried using the Newtonsoft.Json.JsonSerializer via the ISerializer implementation contributed by Daniel Crenna (@dimebrain) and that did not work. So out of this box I can now get certain properties from ElasticSearch that I couldn’t before. i.e.:

[JsonProperty(PropertyName = “docs.count”)] [DeserializeAs(Name = “docs.count”)] public string docscount { get; set; }

Thanks for the fix!!!

New release will contain the fix. I also plan to add more sane interfaces for (de)serialisation so people can use whatever they want.

You could try using the Newtonsoft.JSON nuget package as the JSON parser, via the RestSharp.Newtonsoft.JSON library, see RestSharp.Newtonsoft.JSON

I have a quick and dirty solution to this problem. Not real elegant, but works.

IRestResponse response = establishConnection(resource); string s = response.Content; s = s.Replace(“clientside.bitsIn”, “clientsidebitsIn”); s = s.Replace(“clientside.bitsOut”, “clientsidebitsOut”); s = s.Replace(“clientside.curConns”, “clientsidecurConns”); s = s.Replace(“clientside.evictedConns”, “clientsideevictedConns”); s = s.Replace(“clientside.maxConns”, “clientsidemaxConns”); response.Content = s;

This modifies the json data before its deserialized. Hope this helps others.