這裏我使用的實體類我想刪除零和「」從JSON性反應的輸出值數據
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
}
註釋,並使用廣口瓶
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.6.0</version>
</dependency>
我的電流輸出
{
"mid":"1",
"location":"",
"department":"IT"
"role":"Developer",
"tenent_id":"",
"cid":"1001",
"categoryDTOAL":null
}
預計產量
{
"mid":"1",
"department":"IT"
"role":"Developer",
"cid":"1001",
}
如何我是解決這個問題時,我的這個註解失敗,如果你想忽略空或「」值,那麼你可以TRU
@JsonInclude(Include.NON_NULL)
或@JsonInclude(Include.NON_EMPTY)
begore類來解決這個問題
看到這個答案https://stackoverflow.com/a/16089705/2310289 –
最後我m到處回答 ' org.codehaus.jackson 傑克遜映射器 - 翔升 1.5.0 '添加此jar並使用Annotation'@JsonSerialize(include = JsonSerialize.Inclusion.NON_EMPTY)'這裏我導入'import org.codehaus.jackson.map.annotate.JsonSerialize;' –