是否有任何额外的配置需要让 ServiceStack 将 JSON 请求反序列化为适当的动态对象?我已经编译了包含 DynamicJson 类的 ServiceStack.Text 库的 Net40 版本,并将其添加到我的项目中。我有一个标准的请求和响应 DTO。请求 DTO 具有动态 (ExpandoObject) 公共属性。一旦进入我的服务操作,动态属性似乎没有正确序列化。在客户端,JSON 被完美地反序列化。
这是我正在使用的内容:
请求、响应和服务
[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 正文
{
"subscription":
{
"name":"foo subscription title",
"description":"the description"
}
}
在发布 JSON 并进入我的服务操作后,快速查看请求会显示dynamic Subscription
为字符串。ServiceStack 可以将 JSON 请求序列化为dynamic
?