I want to remove null and "" values data from JSON responce output [SOLVED]

This question already has an answer here:

  • Jackson serialization: ignore empty values (or null)

    7 answers

here I am using Annotation on Entity class

import java.util.ArrayList;
import com.fasterxml.jackson.annotation.JsonInclude;
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public class MappingDTO {

    private String mid; 
    private String location;
    private String department;
    private String role;
    private String tenent_id;
    private String cid;
    private ArrayList<CategoryDTO> categoryDTOAL;
    //setters and getters
}

and using Jar is

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.6.0</version> 
</dependency>

My Current output

{
"mid":"1",
"location":"",
"department":"IT"
"role":"Developer",
"tenent_id":"",
"cid":"1001",
"categoryDTOAL":null
}

Expected Output

 {
"mid":"1",
"department":"IT"
"role":"Developer",
"cid":"1001",
}

How to i’m solve it when my this Annotation is failed to solve this
problem

if you want to ignore null or “” value then you can tru @JsonInclude(Include.NON_NULL) or @JsonInclude(Include.NON_EMPTY) begore class.

you can find below sample code:

@JsonInclude(Include.NON_NULL) 
public static class Test {

}

you can also use @JsonIgnore on any fix column as per your use case.