FasterXML / jackson-docs

Documentation for the Jackson JSON processor.
719 stars 111 forks source link

How to serialize values which are provided JsonInclude.Include.NON_NULL at class level #12

Closed SawyerFord closed 6 years ago

SawyerFord commented 6 years ago

Currently my application has a class which is as below

 @JsonInclude(JsonInclude.Include.NON_NULL)
  public class Employee {
     Department department;
     String firstName;
     String lastName;
     String address;
     String phoneNumber;
  }

I am capturing the employee object inside the logs where I am converting the object into JSON. I am able to convert the object to JSON but the null values do not get into the JSON.

I have tried the below

 objectMapper.setSerializationInclusion(JsonInclude.Include.ALWAYS);
 generator.setCodec(objectMapper);
 generator.writeObjectField(fieldName, argument);

But not able to get the null values of the fields in JSON. How do I get them?

cowtowncoder commented 6 years ago

This is not a question forum.