Skip to content
Sharp

Networking · interview question

When using Jackson, how can you ensure a field is only serialized if it has a non-null value?

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

Correct answer

C. Use @JsonInclude(Include.NON_NULL).

Why

The @JsonInclude(Include.NON_NULL) annotation is used to ensure that fields are only serialized if they have a non-null value. This helps reduce JSON payload size by excluding unnecessary null fields.

Test yourself on Networking

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

Start free test
All Networking questions →