// Any change to this method should be also applied to spring-jms and spring-messaging // MappingJackson2MessageConverter default constructors private void customizeDefaultFeatures(ObjectMapper objectMapper) { if (!this.features.containsKey(MapperFeature.DEFAULT_VIEW_INCLUSION)) { configureFeature(objectMapper, MapperFeature.DEFAULT_VIEW_INCLUSION, false); } if (!this.features.containsKey(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)) { configureFeature(objectMapper, DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); } }
/** * 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 */ @SuppressWarnings("deprecation") 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.instantiate(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.serializationInclusion != null) { objectMapper.setSerializationInclusion(this.serializationInclusion); } if (this.filters != null) { // Deprecated as of Jackson 2.6, but just in favor of a fluent variant. objectMapper.setFilters(this.filters); } for (Class<?> target : this.mixIns.keySet()) { // Deprecated as of Jackson 2.5, but just in favor of a fluent variant. objectMapper.addMixInAnnotations(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())); } }