Example usage for com.fasterxml.jackson.databind.ser.impl SimpleFilterProvider SimpleFilterProvider

List of usage examples for com.fasterxml.jackson.databind.ser.impl SimpleFilterProvider SimpleFilterProvider

Introduction

In this page you can find the example usage for com.fasterxml.jackson.databind.ser.impl SimpleFilterProvider SimpleFilterProvider.

Prototype

public SimpleFilterProvider() 

Source Link

Usage

From source file:org.oncoblocks.centromere.web.test.controller.CrudControllerIntegrationTests.java

@Test
public void updateTest() throws Exception {

    EntrezGene gene = new EntrezGene(7L, "GeneG", 9606, "", "10", "", "", "protein-coding", null, null, null);
    objectMapper.setFilterProvider(new SimpleFilterProvider()
            .addFilter("fieldFilter", SimpleBeanPropertyFilter.serializeAllExcept()).setFailOnUnknownId(false));
    objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);

    mockMvc.perform(post(BASE_URL).contentType(MediaType.APPLICATION_JSON)
            .content(objectMapper.writeValueAsBytes(gene))).andExpect(status().isCreated());

    gene.setPrimaryGeneSymbol("TEST_GENE");

    mockMvc.perform(put(BASE_URL + "/{id}", 7L).contentType(MediaType.APPLICATION_JSON)
            .content(objectMapper.writeValueAsBytes(gene))).andExpect(status().isCreated())
            .andExpect(jsonPath("$", hasKey("entrezGeneId"))).andExpect(jsonPath("$.entrezGeneId", is(7)))
            .andExpect(jsonPath("$.primaryGeneSymbol", is("TEST_GENE")));

    mockMvc.perform(get(BASE_URL + "/{id}", 7L)).andExpect(status().isOk())
            .andExpect(jsonPath("$.entrezGeneId", is(7)))
            .andExpect(jsonPath("$.primaryGeneSymbol", is("TEST_GENE")));

    geneRepository.delete(7L);//from w ww .ja  v a2 s.  com

}

From source file:de.brendamour.jpasskit.signing.PKSigningUtil.java

private static void createPassJSONFile(final PKPass pass, final File tempPassDir,
        final ObjectMapper jsonObjectMapper) throws IOException, JsonGenerationException, JsonMappingException {
    File passJSONFile = new File(tempPassDir.getAbsolutePath() + File.separator + PASS_JSON_FILE_NAME);

    SimpleFilterProvider filters = new SimpleFilterProvider();

    // haven't found out, how to stack filters. Copying the validation one for now.
    filters.addFilter("validateFilter",
            SimpleBeanPropertyFilter.serializeAllExcept("valid", "validationErrors"));
    filters.addFilter("pkPassFilter", SimpleBeanPropertyFilter.serializeAllExcept("valid", "validationErrors",
            "foregroundColorAsObject", "backgroundColorAsObject", "labelColorAsObject"));
    filters.addFilter("barcodeFilter", SimpleBeanPropertyFilter.serializeAllExcept("valid", "validationErrors",
            "messageEncodingAsString"));
    filters.addFilter("charsetFilter", SimpleBeanPropertyFilter.filterOutAllExcept("name"));
    jsonObjectMapper.setSerializationInclusion(Include.NON_NULL);
    jsonObjectMapper.addMixInAnnotations(Object.class, ValidateFilterMixIn.class);
    jsonObjectMapper.addMixInAnnotations(PKPass.class, PkPassFilterMixIn.class);
    jsonObjectMapper.addMixInAnnotations(PKBarcode.class, BarcodeFilterMixIn.class);
    jsonObjectMapper.addMixInAnnotations(Charset.class, CharsetFilterMixIn.class);

    ObjectWriter objectWriter = jsonObjectMapper.writer(filters);
    objectWriter.writeValue(passJSONFile, pass);
}

From source file:org.apache.james.jmap.json.ParsingWritingObjectsTest.java

@Test
public void writingJsonShouldWorkOnMessage() throws Exception {
    String expected = IOUtils.toString(ClassLoader.getSystemResource("json/message.json"));

    SimpleFilterProvider filterProvider = new SimpleFilterProvider()
            .addFilter(JmapResponseWriterImpl.PROPERTIES_FILTER, SimpleBeanPropertyFilter.serializeAll())
            .addFilter(GetMessagesMethod.HEADERS_FILTER, SimpleBeanPropertyFilter.serializeAll());

    String json = testee.forWriting().setFilterProvider(filterProvider).writeValueAsString(MESSAGE);

    assertThatJson(json).when(IGNORING_ARRAY_ORDER).isEqualTo(expected);

}

From source file:org.apache.james.jmap.methods.GetMessagesMethod.java

private Optional<SimpleFilterProvider> buildOptionalHeadersFilteringFilterProvider(
        MessageProperties properties) {//from  w ww .  jav a 2 s . c o m
    return properties.getOptionalHeadersProperties().map(this::buildHeadersPropertyFilter)
            .map(propertyFilter -> new SimpleFilterProvider().addFilter(HEADERS_FILTER, propertyFilter));
}

From source file:org.apereo.portal.dao.usertype.StatisticsJacksonColumnMapper.java

@Override
protected void customizeObjectMapper(ObjectMapper mapper) {
    //Just operate on fields
    mapper.setVisibility(PropertyAccessor.FIELD, Visibility.ANY);
    mapper.setVisibility(PropertyAccessor.GETTER, Visibility.NONE);
    mapper.setVisibility(PropertyAccessor.IS_GETTER, Visibility.NONE);
    mapper.setVisibility(PropertyAccessor.SETTER, Visibility.NONE);
    mapper.setVisibility(PropertyAccessor.CREATOR, Visibility.NONE);

    //Ignore the empty storedData field in all of the stat summary objects
    filters = new SimpleFilterProvider().addFilter(StoredDataFilterMixIn.FILTER_NAME,
            SimpleBeanPropertyFilter.serializeAllExcept("storedData"));
    mapper.addMixInAnnotations(Object.class, StoredDataFilterMixIn.class);
}

From source file:org.apereo.portal.events.aggr.JpaStatisticalSummaryTest.java

public void testStorelessUnivariateStatistic(StorelessUnivariateStatistic sus, double expected)
        throws Exception {

    assertEquals(expected, sus.getResult(), 0.1);

    final ObjectMapper mapper = new ObjectMapper();
    mapper.findAndRegisterModules();/* w  w  w . j  a  v a2 s  . c  o  m*/

    //Configure Jackson to just use fields
    mapper.setVisibility(PropertyAccessor.FIELD, Visibility.ANY);
    mapper.setVisibility(PropertyAccessor.GETTER, Visibility.NONE);
    mapper.setVisibility(PropertyAccessor.IS_GETTER, Visibility.NONE);
    mapper.setVisibility(PropertyAccessor.SETTER, Visibility.NONE);
    mapper.setVisibility(PropertyAccessor.CREATOR, Visibility.NONE);

    mapper.addMixInAnnotations(Object.class, IgnoreTypeMixIn.class);

    final FilterProvider filters = new SimpleFilterProvider().addFilter("storedDataFilter",
            SimpleBeanPropertyFilter.serializeAllExcept("storedData"));

    final ObjectWriter ssWriter = mapper.writer(filters);
    final ObjectReader ssReader = mapper.reader(sus.getClass());

    final String susString = ssWriter.writeValueAsString(sus);
    System.out.println(susString);
    final StorelessUnivariateStatistic newSus = ssReader.readValue(susString);

    assertEquals(expected, newSus.getResult(), 0.1);
}

From source file:org.springframework.boot.actuate.context.properties.ConfigurationPropertiesReportEndpoint.java

private void applyConfigurationPropertiesFilter(ObjectMapper mapper) {
    mapper.setAnnotationIntrospector(new ConfigurationPropertiesAnnotationIntrospector());
    mapper.setFilterProvider(/*from  w  ww. j a v a  2 s .co  m*/
            new SimpleFilterProvider().setDefaultFilter(new ConfigurationPropertiesPropertyFilter()));
}

From source file:org.springframework.boot.actuate.endpoint.ConfigurationPropertiesReportEndpoint.java

/**
 * Configure PropertyFilter to make sure Jackson doesn't process CGLIB generated bean
 * properties./*from ww  w .j a  v a  2  s  .c  o  m*/
 */
private void applyCglibFilters(ObjectMapper mapper) {
    mapper.setAnnotationIntrospector(new CglibAnnotationIntrospector());
    mapper.setFilters(new SimpleFilterProvider().addFilter(CGLIB_FILTER_ID, new CglibBeanPropertyFilter()));
}

From source file:uk.gov.gchq.gaffer.jsonserialisation.JSONSerialiser.java

public static FilterProvider getFilterProvider(final String... fieldsToExclude) {
    if (null == fieldsToExclude || fieldsToExclude.length == 0) {
        // Use the 'serializeAllExcept' method so it is compatible with older versions of jackson
        return new SimpleFilterProvider().addFilter(FILTER_FIELDS_BY_NAME,
                (BeanPropertyFilter) SimpleBeanPropertyFilter.serializeAllExcept());
    }//from ww  w  .  j  a v  a  2 s.com

    return new SimpleFilterProvider().addFilter(FILTER_FIELDS_BY_NAME,
            (BeanPropertyFilter) SimpleBeanPropertyFilter.serializeAllExcept(fieldsToExclude));
}