问题描述
如何强制在反序列化的 JSON 响应中呈现 __type 信息?我不需要重新序列化这些数据,所以我更愿意删除它.ServiceStack 似乎将此添加到我的模型的字典属性中.
How do you force the __type information from rendering in the deserialized JSON response? I have no need to reserialize this data so I'd prefer to remove it. ServiceStack seems to add this to the dictionary properties of my model.
这是使用 ServiceStack 和 ServiceStack.Text.JsonSerializer
This is using ServiceStack and ServiceStack.Text.JsonSerializer
推荐答案
默认情况下,__type 仅在反序列化需要时才发出,例如您的 DTO 包含接口、抽象类或后期绑定对象类型等.
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.
您可以通过以下方式阻止它被发出:
You can prevent it from ever being emitted with:
JsConfig.ExcludeTypeInfo = true;
否则你总是可以用:
JsConfig.IncludeTypeInfo = true;
这篇关于使用 JsonSerializer 删除 JSON 响应中的具体 __type 信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!