JacksonJsonFieldBodyFilter implements BodyFilter { @Override public String filter(@Nullable final String contentType, final String body) { return JsonMediaType.JSON.test(contentType) ? filter(body) : body; } JacksonJsonFieldBodyFilter(final Collection<String> fieldNames, final String replacement, final JsonFactory factory);  JacksonJsonFieldBodyFilter(final Collection<String> fieldNames, final String replacement); @Override String filter(@Nullable final String contentType, final String body); String filter(final String body);  }
@Test public void testFilterString() throws Exception { String filtered = getFilter("email") .filter(getResource("/user.json")); assertThat(filtered, not(containsString("@entur.org"))); }
@Test public void testFilterNumber() throws Exception { String filtered = getFilter("id") .filter(getResource("/user.json")); assertThat(filtered, not(containsString("18375"))); }
@Test public void testFilterObject() throws Exception { String filtered = getFilter("cars") .filter(getResource("/cars-object.json")); assertThat(filtered, not(containsString("Ford"))); }
@Test public void testFilterArray() throws Exception { String filtered = getFilter("cars") .filter(getResource("/cars-array.json")); assertThat(filtered, not(containsString("Ford"))); }
@Test public void testFilterHugeBodyObject1() throws Exception { String string = getResource("/huge-sample.json"); String filtered = getFilter("name").filter(string); assertThat(filtered, not(containsString("Pena Hudson"))); assertThat(filtered.length(), is(lessThan(string.length()))); }
@Test public void testFilterHugeBodyObject2() throws Exception { Set<String> remove = new HashSet<>(); remove.add("name"); String string = getResource("/huge-sample.json"); String filtered = getFilter(remove).filter("application/json", string); assertThat(filtered, not(containsString("Pena Hudson"))); assertThat(filtered.length(), is(lessThan(string.length()))); }
@Test public void doesNotFilterInvalidJson() throws Exception { String valid = getResource("/cars-array.json").trim(); String invalid = valid.substring(0, valid.length() - 1); String filtered = getFilter("cars").filter(invalid); assertThat(filtered, containsString("Ford")); }
@Test public void doesNotFilterNonJson() throws Exception { String valid = getResource("/cars-array.json").trim(); String invalid = valid.substring(0, valid.length() - 1); String filtered = getFilter("cars").filter("application/xml", invalid); assertThat(filtered, containsString("Ford")); }