List of usage examples for com.fasterxml.jackson.databind.introspect AnnotationIntrospectorPair AnnotationIntrospectorPair
public AnnotationIntrospectorPair(AnnotationIntrospector p, AnnotationIntrospector s)
From source file:com.infinities.nova.util.jackson.JacksonProvider.java
public JacksonProvider() { AnnotationIntrospector introspector = new JaxbAnnotationIntrospector(TypeFactory.defaultInstance()); // if using BOTH JAXB annotations AND Jackson annotations: AnnotationIntrospector secondary = new JacksonAnnotationIntrospector(); ObjectMapper mapper = new ObjectMapper().registerModule(new Hibernate4Module()) .configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false) .setDateFormat(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")) .enable(SerializationFeature.INDENT_OUTPUT) .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) .setAnnotationIntrospector(new AnnotationIntrospectorPair(introspector, secondary)); NullStringSerializer serializer = new NullStringSerializer(); SimpleModule module = new SimpleModule("NullToNoneDeserializer"); module.addSerializer(String.class, serializer); mapper.registerModule(module);/* w ww. ja v a2 s. com*/ // mapper = mapper.setSerializationInclusion(Include) setMapper(mapper); }
From source file:org.bremersee.common.jms.DefaultJmsConverter.java
/** * Default constructor./*from ww w . j ava 2 s . c om*/ */ public DefaultJmsConverter() { objectMapper = new ObjectMapper(); AnnotationIntrospector primary = new JacksonAnnotationIntrospector(); AnnotationIntrospector secondary = new JaxbAnnotationIntrospector(TypeFactory.defaultInstance()); AnnotationIntrospectorPair pair = new AnnotationIntrospectorPair(primary, secondary); objectMapper.setAnnotationIntrospector(pair); }
From source file:org.bremersee.common.web.client.ResponseErrorHandlerImpl.java
/** * Default constructor./*ww w. j av a 2 s. c o m*/ */ public ResponseErrorHandlerImpl() { Jaxb2Marshaller m = new Jaxb2Marshaller(); m.setContextPath(ThrowableMessageDto.class.getPackage().getName()); unmarshaller = 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.bremersee.common.spring.autoconfigure.WebMvcExceptionResolver.java
public WebMvcExceptionResolver() { defaultExceptionMapper = new ThrowableToThrowableDtoMapper(); Jaxb2Marshaller m = new Jaxb2Marshaller(); m.setContextPath(ThrowableDto.class.getPackage().getName()); marshaller = m;/* ww w.j av 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: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);/*from w w w .j a v a 2 s. c o m*/ 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:com.arpnetworking.tsdaggregator.configuration.PipelineConfiguration.java
/** * Create an <code>ObjectMapper</code> for Pipeline configuration. * * @param injector The Guice <code>Injector</code> instance. * @return An <code>ObjectMapper</code> for Pipeline configuration. *///from ww w . j a va 2 s. com public static ObjectMapper createObjectMapper(final Injector injector) { final ObjectMapper objectMapper = ObjectMapperFactory.createInstance(); final SimpleModule module = new SimpleModule("Pipeline"); BuilderDeserializer.addTo(module, PipelineConfiguration.class); final Set<Class<? extends Sink>> sinkClasses = INTERFACE_DATABASE.findClassesWithInterface(Sink.class); for (final Class<? extends Sink> sinkClass : sinkClasses) { BuilderDeserializer.addTo(module, sinkClass); } final Set<Class<? extends Source>> sourceClasses = INTERFACE_DATABASE .findClassesWithInterface(Source.class); for (final Class<? extends Source> sourceClass : sourceClasses) { BuilderDeserializer.addTo(module, sourceClass); } @SuppressWarnings({ "rawtypes", "unchecked" }) final Set<Class<? extends Parser<?>>> parserClasses = INTERFACE_DATABASE .findClassesWithInterface((Class) Parser.class); for (final Class<? extends Parser<?>> parserClass : parserClasses) { BuilderDeserializer.addTo(module, parserClass); } final Set<Class<? extends DynamicConfigurationFactory>> dcFactoryClasses = INTERFACE_DATABASE .findClassesWithInterface(DynamicConfigurationFactory.class); for (final Class<? extends DynamicConfigurationFactory> dcFactoryClass : dcFactoryClasses) { BuilderDeserializer.addTo(module, dcFactoryClass); } objectMapper.registerModules(module); final GuiceAnnotationIntrospector guiceIntrospector = new GuiceAnnotationIntrospector(); objectMapper.setInjectableValues(new GuiceInjectableValues(injector)); objectMapper.setAnnotationIntrospectors( new AnnotationIntrospectorPair(guiceIntrospector, objectMapper.getSerializationConfig().getAnnotationIntrospector()), new AnnotationIntrospectorPair(guiceIntrospector, objectMapper.getDeserializationConfig().getAnnotationIntrospector())); return objectMapper; }
From source file:org.bremersee.common.spring.autoconfigure.ObjectMapperAutoConfiguration.java
private static AnnotationIntrospector findAnnotationIntrospectorPair() { try {//www .ja v a 2 s. c o m 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:fr.norad.jaxrs.doc.plugin.DocGeneratorMojo.java
public DocGeneratorMojo() { objectMapper = new ObjectMapper(); objectMapper.setSerializationInclusion(Include.NON_NULL); objectMapper.setAnnotationIntrospector(new AnnotationIntrospectorPair(new JacksonAnnotationIntrospector(), new JaxbAnnotationIntrospector(TypeFactory.defaultInstance()))); }
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 www .j ava2 s.c o m*/ mapper.getDeserializationConfig().withAppendedAnnotationIntrospector(introspector); mapper.getSerializationConfig().withAppendedAnnotationIntrospector(introspector); return mapper; }