2
votes

I'm having a bit of trouble using ServiceStack's DataContract API + *ServiceClient to get the appropriate deserialization out of a standard XML / JSON REST service. For instance if we take the following output (use accept header to get json):

http://rxnav.nlm.nih.gov/REST/RxTerms/rxcui/198440/allinfo

  1. How would you go about structuring a model object to handle both the JSON output and hte XML output from that service (uses accept headers to get json)?

  2. Would you be required to provide an explicit "Name" parameter in the DataContract and DataMember attributes to get the appropriate deserialization?

  3. How does ServiceStack compare the XML / JSON object names to the Property Names in the model? Are they case sensitive?

  4. Can we get some sort of generic Func delegate API in JsonRestClientAsync to seamlessly integrate our own deserialization mechanisms where we have 3rd party format's to deal with?

Yes I know I can use ServiceStack.Text to do explicit deserialization. I pretty much take on that dependency in all my .NET projects :-)

Thanks,

Anuj

1

1 Answers

5
votes

If it's a 3rd party web service (i.e. not a ServiceStack webservice) than I would only be trying to parse one of their formats, I personally prefer JSON for better resilience if they change their API. IMO it's a losing proposition trying to support different formats with the same model, they can easily break it at any time.

As for ServiceStack's JSON Serializer, in the latest release - the properties are case-insensitive and you can set JsConfig.EmitCamelCaseNames=true to get it emit camelcase names instead. See this unit test.

It also now respects the [DataMember(Name="custom")] parameter if you want the property name to be different to the generated name.