List of usage examples for com.fasterxml.jackson.databind ObjectMapper findModules
public static List<Module> findModules(ClassLoader classLoader)
From source file:ws.salient.knowledge.ClasspathRepository.java
@Override public KnowledgeBase getKnowledgeBase(String knowledgeBaseId) { KieServices kie = KieServices.Factory.get(); KieContainerImpl container = (KieContainerImpl) kie.getKieClasspathContainer(); ObjectMapper json = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) .findAndRegisterModules();// w w w.j ava2s . c o m json.registerModules(ObjectMapper.findModules(container.getClassLoader())); KieBase base = container.getKieBase(KnowledgeRepository.getKnowledgeBaseName(knowledgeBaseId)); InternalKieModule module = container.getKieProject() .getKieModuleForKBase(KnowledgeRepository.getKnowledgeBaseName(knowledgeBaseId)); FSTConfiguration serializer = FSTConfiguration.createDefaultConfiguration(); serializer.setShareReferences(true); serializer.setForceSerializable(false); serializer.setClassLoader(container.getClassLoader()); return new KnowledgeBase(KnowledgeRepository.getKnowledgeBaseName(knowledgeBaseId)).withBase(base) .withContainer(container).withJson(json).withModule(module).withReleaseId(container.getReleaseId()) .withSerializer(serializer); }
From source file:ws.salient.aws.s3.AmazonS3Repository.java
@Override public KnowledgeBase getKnowledgeBase(String knowledgeBaseId) { KnowledgeBase knowledgeBase = knowledgeBases.computeIfAbsent(knowledgeBaseId, (id) -> { ReleaseId releaseId = KnowledgeRepository.getReleaseId(knowledgeBaseId); AbstractKieModule module = getKieModule(releaseId, repositories); KieContainer container = kie.newKieContainer(releaseId); KieBase base = container.getKieBase(KnowledgeRepository.getKnowledgeBaseName(knowledgeBaseId)); FSTConfiguration config = FSTConfiguration.createDefaultConfiguration(); config.setShareReferences(true); config.setForceSerializable(false); config.setClassLoader(container.getClassLoader()); ObjectMapper json = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);/* w ww. ja v a 2 s . com*/ json.registerModules(ObjectMapper.findModules(container.getClassLoader())); json.registerModules(new AmazonModule()); return new KnowledgeBase(KnowledgeRepository.getKnowledgeBaseName(knowledgeBaseId)).withBase(base) .withContainer(container).withJson(json).withModule(module).withReleaseId(releaseId) .withSerializer(config); }); return knowledgeBase; }
From source file:org.springframework.http.converter.json.Jackson2ObjectMapperBuilder.java
/** * Configure an existing {@link ObjectMapper} instance with this builder's * settings. This can be applied to any number of {@code ObjectMappers}. * @param objectMapper the ObjectMapper to configure *//*from w ww.ja v a 2 s .co m*/ public void configure(ObjectMapper objectMapper) { Assert.notNull(objectMapper, "ObjectMapper must not be null"); if (this.findModulesViaServiceLoader) { // Jackson 2.2+ objectMapper.registerModules(ObjectMapper.findModules(this.moduleClassLoader)); } else if (this.findWellKnownModules) { registerWellKnownModulesIfAvailable(objectMapper); } if (this.modules != null) { for (Module module : this.modules) { // Using Jackson 2.0+ registerModule method, not Jackson 2.2+ registerModules objectMapper.registerModule(module); } } if (this.moduleClasses != null) { for (Class<? extends Module> module : this.moduleClasses) { objectMapper.registerModule(BeanUtils.instantiateClass(module)); } } if (this.dateFormat != null) { objectMapper.setDateFormat(this.dateFormat); } if (this.locale != null) { objectMapper.setLocale(this.locale); } if (this.timeZone != null) { objectMapper.setTimeZone(this.timeZone); } if (this.annotationIntrospector != null) { objectMapper.setAnnotationIntrospector(this.annotationIntrospector); } if (this.propertyNamingStrategy != null) { objectMapper.setPropertyNamingStrategy(this.propertyNamingStrategy); } if (this.defaultTyping != null) { objectMapper.setDefaultTyping(this.defaultTyping); } if (this.serializationInclusion != null) { objectMapper.setSerializationInclusion(this.serializationInclusion); } if (this.filters != null) { objectMapper.setFilterProvider(this.filters); } for (Class<?> target : this.mixIns.keySet()) { objectMapper.addMixIn(target, this.mixIns.get(target)); } if (!this.serializers.isEmpty() || !this.deserializers.isEmpty()) { SimpleModule module = new SimpleModule(); addSerializers(module); addDeserializers(module); objectMapper.registerModule(module); } customizeDefaultFeatures(objectMapper); for (Object feature : this.features.keySet()) { configureFeature(objectMapper, feature, this.features.get(feature)); } if (this.handlerInstantiator != null) { objectMapper.setHandlerInstantiator(this.handlerInstantiator); } else if (this.applicationContext != null) { objectMapper.setHandlerInstantiator( new SpringHandlerInstantiator(this.applicationContext.getAutowireCapableBeanFactory())); } }