Skip to content
Sharp

Networking · interview question

When using Jackson, how can you handle a situation where a field should be serialized only if it's not null?

Multiple choiceHardchapter-11-curatedpremiumnetworkingjackson-objectmapper
Choose one answer
Answer and explanation

Correct answer

A. Use @JsonInclude(Include.NON_NULL).

Why

@JsonInclude(Include.NON_NULL) is used to ensure that a field is only serialized if it is not null, thus preventing unnecessary data from being included in the JSON output.

Test yourself on Networking

A free test with instant, explained results. No account needed.

Start free test
All Networking questions →