Are there any extra configurations that are necessary to get ServiceStack to deserialize a JSON request into an appropriate dynamic object? I have compiled the Net40 version of the ServiceStack.Text library that includes the DynamicJson class and have added it to my project(s). I have a standard request and response DTO. The request DTO has a dynamic (ExpandoObject) public property. Once inside my service operation, the dynamic property does not seem to be serialized properly. On the client side, the JSON is deserialized perfectly.
Here is what I am working with:
Request, Response and Service
[Route( "/foo/subscriptions", "POST")]
[DataContract( Name = "UpdateSubscription")]
public class UpdateSubscriptionMessage
: IReturn<UpdateSubscriptionMessageResponse>
{
dynamic _subscription;
public UpdateSubscriptionMessage() {
_subscription = new ExpandoObject();
}
[DataMember( Name = "subscription" )]
public dynamic Subscription {
get { return _subscription; }
set { _subscription = value; }
}
}
[DataContract( Name = "UpdateSubscriptionResponse")]
public class UpdateSubscriptionMessageResponse
{
[DataMember( Name = "success" )]
public bool Success { get; set; }
[DataMember( Name = "subscriptionId" )]
public int Id { get; set; }
}
public class SubscriptionTestService : BaseService
{
private IAdminComponent _adminComponent;
public SubscriptionTestService() : this (null) { }
public SubscriptionTestService(IAdminComponent adminComponent) {
_adminComponent = adminComponent;
}
public UpdateSubscriptionMessageResponse Post( UpdateSubscriptionMessage request)
{
var response = new UpdateSubscriptionMessageResponse();
dynamic subscription = request.Subscription;
return response;
}
}
JSON POST Body
{
"subscription":
{
"name":"foo subscription title",
"description":"the description"
}
}
After posting the JSON and stepping into my service operation, a quick peek at the request shows the dynamic Subscription
as a string. Can ServiceStack serialize the JSON request into a dynamic
?