I need to hide some of the fields in the model class in my response object. I tried to follow this SO answer but with no luck.
when there are getter and setters for a field then the @JsonIgnore annotation doesn't seem to be working. see the following code snippet for clarifications.
@ApiModel(description = "")
public class APIInfoDTO {
private String id = null;
@JsonIgnore //this field will not be hidden when getters and setters are defined..
private String name = null;
private String status = null;
@JsonIgnore // this "info" field is hidden since there are no getters and setters for this field
private String info = "adncusdvshbdvsbvhdb";
/**
**/
@ApiModelProperty(value = "")
@JsonProperty("id")
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
/**
**/
@ApiModelProperty(value = "")
@JsonProperty("name")
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
/**
**/
@ApiModelProperty(value = "")
@JsonIgnore
public String getDescription() {
return description;
}
@JsonProperty("description")
public void setDescription(String description) {
this.description = description;
}
furthermore this is the code snippet for object mapping
public static APIInfoDTO fromAPIToInfoDTO(API api) {
APIInfoDTO apiInfoDTO = new APIInfoDTO();
apiInfoDTO.setDescription(api.getDescription());
apiInfoDTO.setContext(api.getContext());
apiInfoDTO.setId(api.getUUID());
APIIdentifier apiId = api.getId();
apiInfoDTO.setName(apiId.getApiName());
apiInfoDTO.setVersion(apiId.getVersion());
apiInfoDTO.setProvider(apiId.getProviderName());
apiInfoDTO.setStatus(api.getStatus().toString());
String providerName = api.getId().getProviderName();
apiInfoDTO.setProvider(APIUtil.replaceEmailDomainBack(providerName));
return apiInfoDTO;
}
any helpful answer would be highly appreciated.. Thanks
[UPDATE] The @JsonIgnore works with org.codehaus.jackson:jackson-core-asl:1.8.6 but fails with com.fasterxml.jackson.core:jackson-annotations:2.7.2.. Any idea why???