Search in sources :

Example 1 with ApiAnnotationIntrospector

use of com.google.api.server.spi.config.annotationreader.ApiAnnotationIntrospector in project endpoints-java by cloudendpoints.

the class ObjectMapperUtil method createStandardObjectMapper.

/**
 * Creates an Endpoints standard object mapper that allows unquoted field names and unknown
 * properties.
 *
 * Note on unknown properties: When Apiary FE supports a strict mode where properties
 * are checked against the schema, BE can just ignore unknown properties.  This way, FE does
 * not need to filter out everything that the BE doesn't understand.  Before that's done,
 * a property name with a typo in it, for example, will just be ignored by the BE.
 */
public static ObjectMapper createStandardObjectMapper(ApiSerializationConfig config) {
    ObjectMapper objectMapper = new ObjectMapper().configure(JsonParser.Feature.ALLOW_COMMENTS, true).configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true).configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true).configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false).setBase64Variant(Base64Variants.MODIFIED_FOR_URL).setSerializerFactory(BeanSerializerFactory.instance.withSerializerModifier(new DeepEmptyCheckingModifier()));
    AnnotationIntrospector pair = EndpointsFlag.JSON_USE_JACKSON_ANNOTATIONS.isEnabled() ? AnnotationIntrospector.pair(new ApiAnnotationIntrospector(config), new JacksonAnnotationIntrospector()) : new ApiAnnotationIntrospector(config);
    objectMapper.setAnnotationIntrospector(pair);
    return objectMapper;
}
Also used : JacksonAnnotationIntrospector(com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector) JacksonAnnotationIntrospector(com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector) AnnotationIntrospector(com.fasterxml.jackson.databind.AnnotationIntrospector) ApiAnnotationIntrospector(com.google.api.server.spi.config.annotationreader.ApiAnnotationIntrospector) ApiAnnotationIntrospector(com.google.api.server.spi.config.annotationreader.ApiAnnotationIntrospector) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

AnnotationIntrospector (com.fasterxml.jackson.databind.AnnotationIntrospector)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 JacksonAnnotationIntrospector (com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector)1 ApiAnnotationIntrospector (com.google.api.server.spi.config.annotationreader.ApiAnnotationIntrospector)1