Avoiding null variables while serializing with Jackson

I perform some CRUD operation by consuming REST APIs. Some of the entities I want to create do not have values for non-mandatory fields. When I pass those entities to servers, the call breaks with a NullPointerException. Hence I do not want to send a variable if it is null. We shall use JsonInclude annotation as shown below

@JsonInclude(JsonInclude.Include.NON_NULL)
String to;

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top