Java Code Examples for com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter#serializeAllExcept()
The following examples show how to use
com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter#serializeAllExcept() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IgnoreFieldsWithFilterUnitTest.java From tutorials with MIT License | 6 votes |
@Test public final void givenTypeHasFilterThatIgnoresFieldByName_whenDtoIsSerialized_thenCorrect() throws JsonParseException, IOException { final ObjectMapper mapper = new ObjectMapper(); final SimpleBeanPropertyFilter theFilter = SimpleBeanPropertyFilter.serializeAllExcept("intValue"); final FilterProvider filters = new SimpleFilterProvider().addFilter("myFilter", theFilter); final MyDtoWithFilter dtoObject = new MyDtoWithFilter(); dtoObject.setIntValue(12); final String dtoAsString = mapper.writer(filters) .writeValueAsString(dtoObject); assertThat(dtoAsString, not(containsString("intValue"))); assertThat(dtoAsString, containsString("booleanValue")); assertThat(dtoAsString, containsString("stringValue")); System.out.println(dtoAsString); }
Example 2
Source File: IgnoreFieldsWithFilterUnitTest.java From tutorials with MIT License | 6 votes |
@Test public final void givenTypeHasFilterThatIgnoresFieldByName_whenDtoIsSerialized_thenCorrect() throws JsonParseException, IOException { final ObjectMapper mapper = new ObjectMapper(); final SimpleBeanPropertyFilter theFilter = SimpleBeanPropertyFilter.serializeAllExcept("intValue"); final FilterProvider filters = new SimpleFilterProvider().addFilter("myFilter", theFilter); final MyDtoWithFilter dtoObject = new MyDtoWithFilter(); dtoObject.setIntValue(12); final String dtoAsString = mapper.writer(filters) .writeValueAsString(dtoObject); assertThat(dtoAsString, not(containsString("intValue"))); assertThat(dtoAsString, containsString("booleanValue")); assertThat(dtoAsString, containsString("stringValue")); System.out.println(dtoAsString); }
Example 3
Source File: Trace.java From heimdall with Apache License 2.0 | 5 votes |
private ObjectMapper mapper() { SimpleBeanPropertyFilter customFilter; if (!this.printFilters) { customFilter = SimpleBeanPropertyFilter.serializeAllExcept("filters"); } else { customFilter = SimpleBeanPropertyFilter.serializeAll(); } FilterProvider filters = new SimpleFilterProvider().addFilter("customFilter", customFilter); return new ObjectMapper().setFilterProvider(filters); }
Example 4
Source File: MetricsHttpSink.java From beam with Apache License 2.0 | 5 votes |
private String serializeMetrics(MetricQueryResults metricQueryResults) throws Exception { SimpleModule module = new JodaModule(); module.addSerializer(new MetricNameSerializer(MetricName.class)); module.addSerializer(new MetricKeySerializer(MetricKey.class)); module.addSerializer(new MetricResultSerializer(MetricResult.class)); objectMapper.registerModule(module); objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); objectMapper.configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true); // need to register a filter as soon as @JsonFilter annotation is specified. // So specify an pass through filter SimpleBeanPropertyFilter filter = SimpleBeanPropertyFilter.serializeAll(); SimpleFilterProvider filterProvider = new SimpleFilterProvider(); filterProvider.addFilter("committedMetrics", filter); objectMapper.setFilterProvider(filterProvider); String result; try { result = objectMapper.writeValueAsString(metricQueryResults); } catch (JsonMappingException exception) { if ((exception.getCause() instanceof UnsupportedOperationException) && exception.getCause().getMessage().contains("committed metrics")) { filterProvider.removeFilter("committedMetrics"); filter = SimpleBeanPropertyFilter.serializeAllExcept("committed"); filterProvider.addFilter("committedMetrics", filter); result = objectMapper.writeValueAsString(metricQueryResults); } else { throw exception; } } return result; }
Example 5
Source File: ObjectMapperExceptField.java From bonita-ui-designer with GNU General Public License v2.0 | 5 votes |
public ObjectMapperExceptField(Class<?> targetClass, String property) { super(); SimpleBeanPropertyFilter theFilter = SimpleBeanPropertyFilter.serializeAllExcept(property); FilterProvider filters = new SimpleFilterProvider().addFilter("myFilter", theFilter); addMixInAnnotations(targetClass, PropertyFilterMixIn.class); setFilters(filters); }
Example 6
Source File: ResponseTransformationFilter.java From minnal with Apache License 2.0 | 5 votes |
@Override public ObjectWriter modify(EndpointConfigBase<?> endpoint, MultivaluedMap<String, Object> responseHeaders, Object valueToWrite, ObjectWriter w, JsonGenerator g) throws IOException { SimpleBeanPropertyFilter filter = null; if (includes != null && !includes.isEmpty()) { filter = new SimpleBeanPropertyFilter.FilterExceptFilter(includes); } else if (excludes != null && !excludes.isEmpty()) { filter = SimpleBeanPropertyFilter.serializeAllExcept(excludes); } else { filter = SimpleBeanPropertyFilter.serializeAllExcept(new HashSet<String>()); } FilterProvider provider = new SimpleFilterProvider().addFilter("property_filter", filter); return w.with(provider); }
Example 7
Source File: JacksonMixInFilterModule.java From camunda-bpm-elasticsearch with Apache License 2.0 | 5 votes |
public static SimpleFilterProvider getCustomFilterProvider() { SimpleFilterProvider filterProvider = new SimpleFilterProvider(); for (Map.Entry<Class<? extends HistoryEvent>, Class> mixInFilter : getDefaultMixInFilters().entrySet()) { String jsonFilterId = getJsonFilterAnnotationValue(mixInFilter.getValue()); if (jsonFilterId != null) { SimpleBeanPropertyFilter filter = SimpleBeanPropertyFilter.serializeAllExcept(""); // TODO: add extension mechanism to declare filter values via ElasticSearchHistoryPluginConfiguration filterProvider.addFilter(jsonFilterId, filter); } } return filterProvider; }