Reputation: 12958
I am developing a REST API. In one of my endpoints, my model (pojo) looks like this:
public class Tax{
String name;
Float value;
}
Anyway, I want to hide the field 'value' in my JSON response, if it's negative (-1 in my case). Is there any jackson annotation for this purpose or any other workaround?
Upvotes: 2
Views: 390
Reputation: 12958
I finally found the most sensible answer.
import com.fasterxml.jackson.annotation.JsonInclude;
make the default value of that attribute to -1.
@JsonInclude(JsonInclude.Include.NON_DEFAULT)
public class Tax{
String name;
Float value = -1;
}
Upvotes: 3