List of usage examples for com.fasterxml.jackson.databind.introspect JacksonAnnotationIntrospector JacksonAnnotationIntrospector
JacksonAnnotationIntrospector
From source file:com.google.api.server.spi.ObjectMapperUtil.java
/** * Creates an Endpoints standard object mapper that allows unquoted field names and unknown * properties./*w ww . ja v a2 s . co m*/ * * 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).setSerializerFactory( BeanSerializerFactory.instance.withSerializerModifier(new DeepEmptyCheckingModifier())); AnnotationIntrospector pair = AnnotationIntrospector.pair(new ApiAnnotationIntrospector(config), new JacksonAnnotationIntrospector()); objectMapper.setAnnotationIntrospector(pair); return objectMapper; }
From source file:org.bremersee.common.spring.autoconfigure.WebMvcExceptionResolver.java
public WebMvcExceptionResolver() { defaultExceptionMapper = new ThrowableToThrowableDtoMapper(); Jaxb2Marshaller m = new Jaxb2Marshaller(); m.setContextPath(ThrowableDto.class.getPackage().getName()); marshaller = m;// w w w . j a v a 2 s . c o m objectMapper = new ObjectMapper(); // see http://wiki.fasterxml.com/JacksonJAXBAnnotations AnnotationIntrospector primary = new JacksonAnnotationIntrospector(); AnnotationIntrospector secondary = new JaxbAnnotationIntrospector(TypeFactory.defaultInstance()); AnnotationIntrospectorPair pair = new AnnotationIntrospectorPair(primary, secondary); objectMapper.setAnnotationIntrospector(pair); }
From source file:org.resthub.web.converter.MappingJackson2JsonHttpMessageConverter.java
/** * Construct a new {@code BindingJacksonHttpMessageConverter}. *///from w ww .j a v a 2 s .c o m public MappingJackson2JsonHttpMessageConverter() { super(new MediaType("application", "json", DEFAULT_CHARSET)); objectMapper = new ObjectMapper(); SimpleModule module = new SimpleModule(); module.addAbstractTypeMapping(Page.class, PageResponse.class); objectMapper.registerModule(module); AnnotationIntrospector introspector = new JacksonAnnotationIntrospector(); objectMapper.setAnnotationIntrospector(introspector); objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false); objectMapper.configure(SerializationFeature.INDENT_OUTPUT, true); objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); }
From source file:org.resthub.web.converter.MappingJackson2XmlHttpMessageConverter.java
/** * Construct a new {@code BindingJacksonHttpMessageConverter}. *///w ww . jav a 2 s. com public MappingJackson2XmlHttpMessageConverter() { super(new MediaType("application", "xml", DEFAULT_CHARSET)); JacksonXmlModule xmlModule = new JacksonXmlModule(); xmlModule.setDefaultUseWrapper(false); objectMapper = new XmlMapper(xmlModule); SimpleModule module = new SimpleModule(); module.addAbstractTypeMapping(Page.class, PageResponse.class); objectMapper.registerModule(module); AnnotationIntrospector introspector = new JacksonAnnotationIntrospector(); objectMapper.setAnnotationIntrospector(introspector); }
From source file:eu.modaclouds.sla.mediator.Utils.java
private <E> void printJson(E e) throws JsonProcessingException { ObjectMapper mapper = new ObjectMapper(); AnnotationIntrospector introspector = new JacksonAnnotationIntrospector(); // mapper.getDeserializationConfig().setAnnotationIntrospector(introspector); mapper.getSerializationConfig().with(introspector); System.out.println(mapper.writeValueAsString(e)); }
From source file:edu.psu.swe.scim.server.utility.AttributeUtil.java
@PostConstruct public void init() { // TODO move this to a CDI producer objectMapper = new ObjectMapper(); JaxbAnnotationModule jaxbAnnotationModule = new JaxbAnnotationModule(); objectMapper.registerModule(jaxbAnnotationModule); objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); AnnotationIntrospector jaxbIntrospector = new JaxbAnnotationIntrospector(objectMapper.getTypeFactory()); AnnotationIntrospector jacksonIntrospector = new JacksonAnnotationIntrospector(); AnnotationIntrospector pair = new AnnotationIntrospectorPair(jacksonIntrospector, jaxbIntrospector); objectMapper.setAnnotationIntrospector(pair); objectMapper.setSerializationInclusion(Include.NON_NULL); SimpleModule module = new SimpleModule(); module.addDeserializer(ScimResource.class, new ScimResourceDeserializer(this.registry, this.objectMapper)); objectMapper.registerModule(module); }
From source file:com.abiquo.apiclient.stream.StreamClient.java
private StreamClient(final String endpoint, final String username, final String password, final SSLConfiguration sslConfiguration) { this.endpoint = checkNotNull(endpoint, "endpoint cannot be null"); checkNotNull(username, "username cannot be null"); checkNotNull(password, "password cannot be null"); AsyncHttpClientConfig.Builder config = new AsyncHttpClientConfig.Builder(); config.setRequestTimeoutInMs(-1);// w ww .j av a 2 s . c om config.setIdleConnectionTimeoutInMs(-1); if (sslConfiguration != null) { config.setHostnameVerifier(sslConfiguration.hostnameVerifier()); config.setSSLContext(sslConfiguration.sslContext()); } config.setRealm(new Realm.RealmBuilder() // .setPrincipal(username) // .setPassword(password) // .setUsePreemptiveAuth(true) // .setScheme(Realm.AuthScheme.BASIC) // .build()); clientConfig = config.build(); json = new ObjectMapper().setAnnotationIntrospector( // new AnnotationIntrospectorPair(new JacksonAnnotationIntrospector(), new JaxbAnnotationIntrospector(TypeFactory.defaultInstance()))) // .registerModule(new AbiquoModule()); }
From source file:org.bremersee.common.spring.autoconfigure.ObjectMapperAutoConfiguration.java
private static AnnotationIntrospector findAnnotationIntrospectorPair() { try {//from w w w. j a v a 2 s . c om LOG.info("Trying to add a pair of annotation introspectors ('" + JacksonAnnotationIntrospector.class.getSimpleName() + " + " + JAXB_ANNOTATION_INTROSPECTOR_CLASS_NAME + ")."); @SuppressWarnings("unchecked") Class<? extends AnnotationIntrospector> cls = (Class<? extends AnnotationIntrospector>) Class .forName(JAXB_ANNOTATION_INTROSPECTOR_CLASS_NAME); Constructor<? extends AnnotationIntrospector> constructor = cls.getConstructor(TypeFactory.class); AnnotationIntrospector secondary = constructor.newInstance(TypeFactory.defaultInstance()); // see http://wiki.fasterxml.com/JacksonJAXBAnnotations AnnotationIntrospector primary = new JacksonAnnotationIntrospector(); AnnotationIntrospectorPair pair = new AnnotationIntrospectorPair(primary, secondary); LOG.info("The pair of annotation introspectors ('" // NOSONAR + JacksonAnnotationIntrospector.class.getSimpleName() + " + " + JAXB_ANNOTATION_INTROSPECTOR_CLASS_NAME + ") was successfully added."); return pair; } catch (ClassNotFoundException e) { // NOSONAR LOG.warn("The pair of annotation introspectors ('" + JacksonAnnotationIntrospector.class.getSimpleName() + " " + "+ " + JAXB_ANNOTATION_INTROSPECTOR_CLASS_NAME + ") wasn't added: " + JAXB_ANNOTATION_INTROSPECTOR_CLASS_NAME + " was not found."); } catch (NoSuchMethodException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { LOG.warn("The pair of annotation introspectors ('" + JacksonAnnotationIntrospector.class.getSimpleName() + " " + "+ " + JAXB_ANNOTATION_INTROSPECTOR_CLASS_NAME + ") wasn't added.", e); } return null; }
From source file:org.openengsb.core.util.JsonUtils.java
public static ObjectMapper createObjectMapperWithIntroSpectors() { ObjectMapper mapper = new ObjectMapper(); AnnotationIntrospector primaryIntrospector = new JacksonAnnotationIntrospector(); AnnotationIntrospector secondaryIntrospector = new JaxbAnnotationIntrospector(mapper.getTypeFactory()); AnnotationIntrospector introspector = new AnnotationIntrospectorPair(primaryIntrospector, secondaryIntrospector);//from w w w . j a va 2 s .c om mapper.getDeserializationConfig().withAppendedAnnotationIntrospector(introspector); mapper.getSerializationConfig().withAppendedAnnotationIntrospector(introspector); return mapper; }
From source file:org.jbr.taskmgr.config.WebMvcConfig.java
private MappingJackson2HttpMessageConverter createMappingJackson2HttpMessageConverter() { final MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter(); final ObjectMapper objectMapper = new ObjectMapper(); objectMapper.setAnnotationIntrospector(new JacksonAnnotationIntrospector()); converter.setObjectMapper(objectMapper); return converter; }