use of com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider in project tutorials by eugenp.
the class JsonFilterUnitTest method whenSerializingUsingJsonFilter_thenCorrect.
@Test
public void whenSerializingUsingJsonFilter_thenCorrect() throws JsonProcessingException {
// arrange
Author author = new Author("Alex", "Theedom");
FilterProvider filters = new SimpleFilterProvider().addFilter("authorFilter", SimpleBeanPropertyFilter.filterOutAllExcept("lastName"));
// act
String result = new ObjectMapper().writer(filters).writeValueAsString(author);
// assert
assertThat(from(result).getList("items")).isNull();
/*
{
"lastName": "Theedom"
}
*/
}
use of com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider in project logging-log4j2 by apache.
the class AbstractJacksonFactory method newWriter.
public ObjectWriter newWriter(final boolean locationInfo, final boolean properties, final boolean compact, final boolean includeMillis) {
final SimpleFilterProvider filters = new SimpleFilterProvider();
final Set<String> except = new HashSet<>(5);
if (!locationInfo) {
except.add(this.getPropertyNameForSource());
}
if (!properties) {
except.add(this.getPropertyNameForContextMap());
}
if (!includeStacktrace) {
except.add(this.getPropertyNameForStackTrace());
}
if (includeMillis) {
except.add(getPropertyNameForInstant());
} else {
except.add(getPropertyNameForTimeMillis());
}
except.add(this.getPropertyNameForNanoTime());
filters.addFilter(Log4jLogEvent.class.getName(), SimpleBeanPropertyFilter.serializeAllExcept(except));
final ObjectWriter writer = this.newObjectMapper().writer(compact ? this.newCompactPrinter() : this.newPrettyPrinter());
return writer.with(filters);
}
use of com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider in project redisson by redisson.
the class ConfigSupport method createMapper.
private ObjectMapper createMapper(JsonFactory mapping, ClassLoader classLoader) {
ObjectMapper mapper = new ObjectMapper(mapping);
mapper.addMixIn(Config.class, ConfigMixIn.class);
mapper.addMixIn(ReferenceCodecProvider.class, ClassMixIn.class);
mapper.addMixIn(AddressResolverGroupFactory.class, ClassMixIn.class);
mapper.addMixIn(Codec.class, ClassMixIn.class);
mapper.addMixIn(RedissonNodeInitializer.class, ClassMixIn.class);
mapper.addMixIn(LoadBalancer.class, ClassMixIn.class);
mapper.addMixIn(NatMapper.class, ClassMixIn.class);
mapper.addMixIn(NameMapper.class, ClassMixIn.class);
mapper.addMixIn(NettyHook.class, ClassMixIn.class);
FilterProvider filterProvider = new SimpleFilterProvider().addFilter("classFilter", SimpleBeanPropertyFilter.filterOutAllExcept());
mapper.setFilterProvider(filterProvider);
mapper.setSerializationInclusion(Include.NON_NULL);
mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
if (classLoader != null) {
TypeFactory tf = TypeFactory.defaultInstance().withClassLoader(classLoader);
mapper.setTypeFactory(tf);
}
return mapper;
}
use of com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider in project spring-framework by spring-projects.
the class Jackson2ObjectMapperBuilderTests method filters.
@Test
void filters() throws JsonProcessingException {
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json().filters(new SimpleFilterProvider().setFailOnUnknownId(false)).build();
JacksonFilteredBean bean = new JacksonFilteredBean("value1", "value2");
String output = objectMapper.writeValueAsString(bean);
assertThat(output).contains("value1");
assertThat(output).contains("value2");
SimpleFilterProvider provider = new SimpleFilterProvider().setFailOnUnknownId(false).setDefaultFilter(SimpleBeanPropertyFilter.serializeAllExcept("property2"));
objectMapper = Jackson2ObjectMapperBuilder.json().filters(provider).build();
output = objectMapper.writeValueAsString(bean);
assertThat(output).contains("value1");
assertThat(output).doesNotContain("value2");
}
use of com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider in project dhis2-core by dhis2.
the class FieldFilterService method getSimpleFilterProvider.
private SimpleFilterProvider getSimpleFilterProvider(List<FieldPath> fieldPaths, boolean skipSharing) {
SimpleFilterProvider filterProvider = new SimpleFilterProvider();
filterProvider.addFilter("field-filter", new FieldFilterSimpleBeanPropertyFilter(fieldPaths, skipSharing));
return filterProvider;
}
Aggregations