Search code examples
spring-bootannotationsentitymongodb-java

Spring Boot API : If any field is empty in request body it is storing as null in DB


If any field is empty in request body it is storing as null in DB, that is because of entity class I guess. For example : if in entity class a field is there as "name". My question is if I am not passing that "name" attribute in request body it should not store null in DB. How is it possible?


Solution

  • Add @JsonInclude(Include.NON_NULL) Jackson annotation on entity level or attribute level to ignore the empty or null values when serializing json.