在ServiceStack json中返回null值

时间:2017-04-13 10:18:12

标签: c# serialization servicestack

如果object为null,则服务堆栈返回

{}

但我想返回null值,我怎么能实现呢?

我的序列化代码:

    public override Task WriteToStreamAsync(Type type, object value, Stream writeStream, System.Net.Http.HttpContent content, TransportContext transportContext)
    {
        var task = Task.Factory.StartNew(() => JsonSerializer.SerializeToStream(value, type, writeStream));
        return task;
    }

1 个答案:

答案 0 :(得分:3)

在AppHost中添加全局配置:

JsConfig.IncludeNullValues = true;