use of com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider in project openremote by openremote.
the class ValueUtil method configureObjectMapper.
public static ObjectMapper configureObjectMapper(ObjectMapper objectMapper) {
objectMapper.setConstructorDetector(ConstructorDetector.DEFAULT).setSerializationInclusion(JsonInclude.Include.NON_NULL).configure(SerializationFeature.WRITE_EMPTY_JSON_ARRAYS, // see https://github.com/FasterXML/jackson-databind/issues/1547
false).configure(SerializationFeature.WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS, false).enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_ENUMS).configure(DeserializationFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS, false).configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false).setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.NONE).setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY).setVisibility(PropertyAccessor.CREATOR, JsonAutoDetect.Visibility.ANY).registerModule(new Jdk8Module()).registerModule(new JavaTimeModule()).registerModule(new ParameterNamesModule(JsonCreator.Mode.DEFAULT));
objectMapper.configOverride(Map.class).setInclude(JsonInclude.Value.construct(JsonInclude.Include.NON_NULL, JsonInclude.Include.NON_NULL));
SimpleFilterProvider filters = new SimpleFilterProvider();
filters.setFailOnUnknownId(false);
objectMapper.setFilterProvider(filters);
return objectMapper;
}
use of com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider in project instagram-java-scraper by postaddictme.
the class MappingTest method toJson.
private String toJson(Object instance) throws JsonProcessingException {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.addMixIn(Object.class, PropertyFilterMixIn.class);
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
SimpleBeanPropertyFilter theFilter = SimpleBeanPropertyFilter.serializeAllExcept("lastUpdated");
FilterProvider filters = new SimpleFilterProvider().addFilter("skipLastUpdated", theFilter);
objectMapper.enable(SerializationFeature.INDENT_OUTPUT);
return objectMapper.writer(filters).writeValueAsString(instance);
}
use of com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider in project alfresco-remote-api by Alfresco.
the class JsonJacksonTests method testSerializeMultipleObjects.
@Test
public void testSerializeMultipleObjects() throws IOException {
final Collection<Comment> allComments = new ArrayList<Comment>();
Comment aComment = new Comment();
aComment.setContent("<b>There it is</b>");
allComments.add(aComment);
aComment = new Comment();
aComment.setContent("<p>I agree with the author</p>");
allComments.add(aComment);
ByteArrayOutputStream out = new ByteArrayOutputStream();
jsonHelper.withWriter(out, new Writer() {
@Override
public void writeContents(JsonGenerator generator, ObjectMapper objectMapper) throws JsonGenerationException, JsonMappingException, IOException {
FilterProvider fp = new SimpleFilterProvider().addFilter(JacksonHelper.DEFAULT_FILTER_NAME, new ReturnAllBeanProperties());
objectMapper.writer(fp).writeValue(generator, allComments);
}
});
assertTrue(out.toString().contains("content\":\"<b>There it is</b>"));
assertTrue(out.toString().contains("content\":\"<p>I agree with the author</p>"));
}
use of com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider in project logging-log4j2 by apache.
the class JacksonFactory method newWriter.
ObjectWriter newWriter(final boolean locationInfo, final boolean properties, final boolean compact) {
final SimpleFilterProvider filters = new SimpleFilterProvider();
final Set<String> except = new HashSet<>(2);
if (!locationInfo) {
except.add(this.getPropertNameForSource());
}
if (!properties) {
except.add(this.getPropertNameForContextMap());
}
except.add(this.getPropertNameForNanoTime());
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 gravitee-management-rest-api by gravitee-io.
the class ApiService_DeleteTest method setUp.
@Before
public void setUp() {
PropertyFilter apiMembershipTypeFilter = new ApiPermissionFilter();
objectMapper.setFilterProvider(new SimpleFilterProvider(Collections.singletonMap("apiMembershipTypeFilter", apiMembershipTypeFilter)));
}
Aggregations