0

I'm currently creating a library that will handle ApiResponses in .NET

What it looks like at the moment:

ApiResponse{}
SuccessfulResponse: ApiResponse{}
FailedResponse: ApiResponse{}

I'm trying to create an EmptySuccessfulResponse for 204 responses, but the issue is that Newtonsoft.Json will always add the curly braces.

My main question is: Is there an annotation like [JsonIgnore] but for an entire class? The reason for that is to avoid a return null; in my Controller.

Mathias
  • 1,819
  • 4
  • 22
  • 34
Yvan Lourenço
  • 190
  • 1
  • 9
  • 2
    These responses are built-in already – Pavel Anikhouski Jul 16 '20 at 08:55
  • A zero-length string is not well-formed JSON, as a zero-length string value is serialized to JSON as `""`. Thus the minimum valid JSON is `[]`, `{}`, `""`, `0` or `null`. See [What is the minimum valid JSON?](https://stackoverflow.com/q/18419428/3744182). – dbc Jul 16 '20 at 15:22
  • Thus, for instance, Json.NET serializes as `null` **root** value as `null` even when `NullValueHandling = NullValueHandling.Ignore`, see https://dotnetfiddle.net/y0Bc4E – dbc Jul 16 '20 at 16:04

0 Answers0