glazjoon
glazjoon

Reputation: 654

Is there a setting to keep empty lists during JSON serialization in ServiceStack?

As the title says, is there a way to keep empty lists during JSON serialization in ServiceStack?

Upvotes: 0

Views: 33

Answers (1)

mythz
mythz

Reputation: 143409

ServiceStack.Text JSON Serializer, already serializes empty lists by default:

using ServiceStack;
using ServiceStack.Text;

Console.WriteLine(new Test().ToJson());

public class Test
{
    public List<string> List { get; set; } = new();
}

Output:

{"List":[]}

Upvotes: 1

Related Questions