Reputation: 2051
I run a test, returning as response a dynamic object (ExpandoObject).
It works, but the JsonServiceClient cannot convert the object
and returns in json format the data and type descriptions.
Can we do something better ?
public class DynamicAPIRequest : IReturn<object>
{ ... }
public object Post(DynamicAPIRequest request)
{
dynamic response = new ExpandoObject();
response.Name = "Donald Duck";
response.Nephews = new List<nephew>();
response.Nephews.Add(new nephew { name = "Huey" } );
...
return response;
}
In client side
var nephews = client.Post<object>(new DynamicAPIRequest { uncle = "skroutz" });
/* returns
{Name:Donald Duck,Nephews:[{__type:Test.Client.Model.nephew,
Test.Client.Model,name:Huey},{name:Dewey},{name:Louie}]}
*/
What other can I do ?
Upvotes: 1
Views: 958
Reputation: 1837
To get rid of the __type
properties you will need set the configuration for serialization to exclude type info:
JsConfig.ExcludeTypeInfo = true;
From mythz in this answer:
By default the __type is only emitted when it's required for deserialization, e.g. your DTO contains an interface, abstract class or late-bound object type, etc.
Upvotes: 3