Web-Anchor icon indicating copy to clipboard operation
Web-Anchor copied to clipboard

Handling different cases

Open daniel-tell opened this issue 9 years ago • 3 comments

It would be nice if you could pass the case (i.e. camelCase, snake_case etc.) of the api as a parameter, or even better if WebAnchor could recognize it automatically.

daniel-tell avatar Dec 21 '15 15:12 daniel-tell

The default serializer is the JSON.NET JsonSerializer which has a ContractResolver-property that can be used to change how json is serialized (like the CamelCasePropertyNamesContractResolver). So this can be applied for web anchor like this:

            var myApi = Api.For<ITestApi>(host, new ApiSettings
            {
                ContentSerializer = new ContentSerializer(new JsonSerializer
                {
                    ContractResolver = new CamelCasePropertyNamesContractResolver()
                })
            });

carl-berg avatar Dec 21 '15 16:12 carl-berg

In this case I know it is about deserializing. The same JsonSerializer that Carl suggests can be used when creating the response parser as well.

mattiasnordqvist avatar Dec 21 '15 20:12 mattiasnordqvist

Maybe we should be clearer on where to modify serialization. The name ContentSerializer does really reveal wheather it is used for Request content serialization or Reponse content serialization...

Also changing reponse serialization is little bit harder to get to in order to change it (if you don't know where to look), but that's easily solved by documentation

carl-berg avatar Dec 22 '15 11:12 carl-berg