Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I control property names (casing) of JSON-deserialised objects through service/WebInvoke methods
    text
    copied!<p>I'm hosting a service using code like this:</p> <pre><code>// Set up the test service testServiceHost = new WebServiceHost(typeof(TestTrelloService), testServiceAddress); testServiceHost.Open(); </code></pre> <p>And I'm sending a PUT with RestSharp, to a method like this:</p> <pre><code>[OperationContract] [WebInvoke(Method = "PUT", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare, UriTemplate = "cards/{cardId}?key={key}")] public void UpdateCard(string key, string cardId, Card updatedCard) { // ... } </code></pre> <p><code>key</code> and <code>cardId</code> are coming from the url/querystring, and updatedCard is the request body (s JSON).</p> <p>Everything works fine if my Card class looks like this:</p> <pre><code>public class Card { public string id { get; set; } // ... } </code></pre> <p>The JSON data passed in the body is correctly deserialised into a <code>Card</code> object with the <code>id</code> propert set.</p> <p>However, I want my class to have different casing on the property. It actually looks like this:</p> <pre><code>public class Card { public string Id { get; set; } } </code></pre> <p>However, this doesn't work. I've tried adding various attributes to try and control this (including <code>[DataMember(Name="id")]</code>), but nothing seems to work.</p> <p>Is there a way I can control the property names for the JSON deserialisation done for my <code>WebInvoke</code>/service method?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload