1

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 ?

stefan2410
  • 1,931
  • 2
  • 16
  • 21

1 Answers1

3

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.

Community
  • 1
  • 1
Mike
  • 1,837
  • 10
  • 9
  • Mike thanks it works, excluding the type info. I still have another problem, how to derialize the json to a var type ( I tested DynamicJson.Deserialize in v4 -net.4 but without results) – stefan2410 Oct 02 '13 at 15:50