Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ignore Jackson @JsonFilter annotated on class

Tags:

jackson

I have the code below... I want Jackson to ignore the @JsonFilter on a class in the else condition below. I only want it to consider the @JsonFilter in the event I have some filters.

@JsonFilter("filter")
public class Test {

}


  if (filters != null)
        mapper.writer(filters).writeValue(jsonGenerator,
                response.getOriginalResponse());
    else
        mapper.writeValue(jsonGenerator, response.getOriginalResponse());
like image 953
chrislhardin Avatar asked Oct 29 '25 14:10

chrislhardin


1 Answers

I did this to bypass the filter in the else condition.

     SimpleFilterProvider dummy = new SimpleFilterProvider();
        dummy.setFailOnUnknownId(false);
        mapper.writer(dummy).writeValue(jsonGenerator,
                response.getOriginalResponse());
like image 95
chrislhardin Avatar answered Oct 31 '25 11:10

chrislhardin