Example usage for com.fasterxml.jackson.annotation PropertyAccessor IS_GETTER

List of usage examples for com.fasterxml.jackson.annotation PropertyAccessor IS_GETTER

Introduction

In this page you can find the example usage for com.fasterxml.jackson.annotation PropertyAccessor IS_GETTER.

Prototype

PropertyAccessor IS_GETTER

To view the source code for com.fasterxml.jackson.annotation PropertyAccessor IS_GETTER.

Click Source Link

Document

"Is getters" are getter-like methods that are named "isXxx" (instead of "getXxx" for getters) and return boolean value (either primitive, or java.lang.Boolean ).

Usage

From source file:com.strategicgains.restexpress.serialization.json.DefaultJsonProcessor.java

/**
 * Template method for sub-classes to augment the mapper with desired
 * settings.  Sub-classes should call super() to get default settings.
 * //from w w  w  .j  av  a 2s  .co  m
 * @param module a SimpleModule
 */
protected void initializeMapper(ObjectMapper mapper) {
    mapper
            //         .enable(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT)
            .disable(SerializationFeature.FAIL_ON_EMPTY_BEANS)

            // Ignore additional/unknown properties in a payload.
            .disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)

            // Only serialize populated properties (do no serialize nulls)
            .setSerializationInclusion(JsonInclude.Include.NON_NULL)

            // Use fields directly.
            .setVisibility(PropertyAccessor.FIELD, Visibility.ANY)

            // Ignore accessor and mutator methods (use fields per above).
            .setVisibility(PropertyAccessor.GETTER, Visibility.NONE)
            .setVisibility(PropertyAccessor.SETTER, Visibility.NONE)
            .setVisibility(PropertyAccessor.IS_GETTER, Visibility.NONE)

            // Set default date output format.
            .setDateFormat(new SimpleDateFormat(DateAdapterConstants.TIME_POINT_OUTPUT_FORMAT));
}

From source file:org.jasig.cas.util.AbstractJacksonBackedJsonSerializer.java

/**
 * Initialize object mapper.// www. java2s  .c o  m
 *
 * @return the object mapper
 */
protected ObjectMapper initializeObjectMapper() {
    final ObjectMapper mapper = new ObjectMapper();
    mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
    mapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
    mapper.setVisibility(PropertyAccessor.SETTER, JsonAutoDetect.Visibility.PROTECTED_AND_PUBLIC);
    mapper.setVisibility(PropertyAccessor.GETTER, JsonAutoDetect.Visibility.PROTECTED_AND_PUBLIC);
    mapper.setVisibility(PropertyAccessor.IS_GETTER, JsonAutoDetect.Visibility.PROTECTED_AND_PUBLIC);
    mapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.As.PROPERTY);
    return mapper;
}

From source file:com.ikanow.aleph2.data_model.utils.BeanTemplateUtils.java

/** Configures a mapper with the desired properties for use in Aleph2
 * @param configure_me - leave this empty to create a new mapper, or add one to configure an existing mapper
 * @return// w w  w .ja  v a  2 s  . c o m
 */
public static ObjectMapper configureMapper(final Optional<ObjectMapper> configure_me) {
    final ObjectMapper mapper = configure_me.orElse(new ObjectMapper());
    mapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
    mapper.setVisibility(PropertyAccessor.FIELD, Visibility.ANY);
    mapper.setSerializationInclusion(Include.NON_NULL);
    mapper.setVisibility(PropertyAccessor.IS_GETTER, JsonAutoDetect.Visibility.NONE);

    final SimpleModule module = new SimpleModule();
    module.addDeserializer(Number.class, new NumberDeserializer());
    mapper.registerModule(module);

    return mapper;
}

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 ww  .  ja  v  a2s .  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);
}