3

Is it possible in service stack to include/exclude null values at a DTO/property level rather than on the whole using "JsConfig.IncludeNullValues". I have a scenario where i need specific responses to have null values in the returned JSON.

  • Please refer the following link http://stackoverflow.com/questions/14881270/is-there-a-way-to-ignore-default-values-during-serialization-with-servicestack-j – Shiljo Paulson Jul 31 '14 at 10:02

1 Answers1

2

Using JsConfig scope block, just drop these lines into your AppHost Configure method:

JsConfig<NotNullDtoResponse>.RawSerializeFn = (obj) =>
{
    using(JsConfig.With(new Config { IncludeNullValues = true }))
    {
        return obj.ToJson();
    }
};

JsConfig<NotNullDtoResponse>.RawDeserializeFn = (json) =>
{
    using(JsConfig.With(new Config { IncludeNullValues = true }))
    {
        return JsonSerializer.DeserializeFromString<NotNullDtoResponse>(json);
    }
};

NotNullDtoResponse is your responseDTO

mythz
  • 141,670
  • 29
  • 246
  • 390
Rachid
  • 812
  • 6
  • 7