fastify reply: treat null as undefined

Viewed 123

When working with Java, annotation @JsonInclude(Include.NON_NULL) causes null values to be omitted from the final JSON output. For example, object {a: 5, b: null} is serialized to {a: 5}.

Fastify/Typescript already behave similarly on undefined values. For example, object {a: 5, b: undefined} is serialized to {a: 5}.

But is there a way to get Fastify/Typescript to work similarly on null values? Currently, object {a: 5, b: null} is serializing to {a: 5, b: null} instead of {a: 5}.

My solution so far has been to individually inspect fields and replace null with undefined, but this is cumbersome and error prone. Hoping to find a cleaner solution!

0 Answers
Related