using ServiceStack;
using ServiceStack.Text;
JsConfig<string>.DeSerializeFn = str => str?.Trim();
public class Test
{
public string Name { get; set; }
public string Age { get; set; }
public string Description { get; set; }
}
var dto = new Test { Name = " John Doe ", Age = "18" };
var json = dto.ToJson(); //= {"Name":" John Doe ","Age":"18"}
var fromDto = json.FromJson<Test>();
var isDescriptionNull = fromDto.Description == null; //= true
I have a small example reproducing the issue but there are a handful of files involved and I don’t see how that would work with gist. It’s doing more then just .ToJson/.FromJson, a client and server are involved. Is there a way I can send a zip?
The problem appears to be how null values are serialized for the request object. Newtonsoft for example serializes to “{”[property name]":null}" but ServiceStack.Text serializes to “{}”. If the property is serialized to “{}” the behavior is as expected.
Is there a way to ignore null like “{”[property name]":null}"? I’ve tried “JsConfig.IncludeNullValues = false” in the Configure method but that doesn’t do it.