简体   繁体   中英

How do I prevent ServiceStack deserializing empty request parameter values as null?

I have a very simple ServiceStack service which I am invoking it via JSONServiceClient and c# typed API.

However, when I have empty arguments in Request params, ServiceStack is deserializing this into null values. I have looked and it seems like in JSV it is by design but JSON should retain non null values as they are. I have now also set following two settings in Global.asax.cs but with no improvement:

JsConfig.IncludeNullValues = true;
JsConfig.ThrowOnDeserializationError = true;

I'm using ServiceStack version 3.9.69 and IIS version 8.0.

Do you need to differentiate between Null and Empty Strings? If not, then treat them as the same thing, you can check for them using string.IsNullOrEmpty(string str)

From a quick Google of the issue, it seems as a known problem, so you are going to need to work around it. Perhaps before serializing the, configure null values to a string "NULL"?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM