|
98 | 98 | */
|
99 | 99 | public class Jackson2ObjectMapperBuilder {
|
100 | 100 |
|
| 101 | + private static volatile boolean kotlinWarningLogged = false; |
| 102 | + |
101 | 103 | private final Log logger = LogFactory.getLog(getClass());
|
102 | 104 |
|
103 | 105 | private final Map<Class<?>, Class<?>> mixIns = new HashMap<>();
|
@@ -543,7 +545,7 @@ public Jackson2ObjectMapperBuilder modulesToInstall(Class<? extends Module>... m
|
543 | 545 |
|
544 | 546 | /**
|
545 | 547 | * Set whether to let Jackson find available modules via the JDK ServiceLoader,
|
546 |
| - * based on META-INF metadata in the classpath. Requires Jackson 2.2 or higher. |
| 548 | + * based on META-INF metadata in the classpath. |
547 | 549 | * <p>If this mode is not set, Spring's Jackson2ObjectMapperBuilder itself
|
548 | 550 | * will try to find the JSR-310 and Joda-Time support modules on the classpath -
|
549 | 551 | * provided that Java 8 and Joda-Time themselves are available, respectively.
|
@@ -616,18 +618,14 @@ public void configure(ObjectMapper objectMapper) {
|
616 | 618 | Assert.notNull(objectMapper, "ObjectMapper must not be null");
|
617 | 619 |
|
618 | 620 | if (this.findModulesViaServiceLoader) {
|
619 |
| - // Jackson 2.2+ |
620 | 621 | objectMapper.registerModules(ObjectMapper.findModules(this.moduleClassLoader));
|
621 | 622 | }
|
622 | 623 | else if (this.findWellKnownModules) {
|
623 | 624 | registerWellKnownModulesIfAvailable(objectMapper);
|
624 | 625 | }
|
625 | 626 |
|
626 | 627 | if (this.modules != null) {
|
627 |
| - for (Module module : this.modules) { |
628 |
| - // Using Jackson 2.0+ registerModule method, not Jackson 2.2+ registerModules |
629 |
| - objectMapper.registerModule(module); |
630 |
| - } |
| 628 | + objectMapper.registerModules(this.modules); |
631 | 629 | }
|
632 | 630 | if (this.moduleClasses != null) {
|
633 | 631 | for (Class<? extends Module> module : this.moduleClasses) {
|
@@ -770,13 +768,15 @@ private void registerWellKnownModulesIfAvailable(ObjectMapper objectMapper) {
|
770 | 768 | if (KotlinDetector.isKotlinPresent()) {
|
771 | 769 | try {
|
772 | 770 | Class<? extends Module> kotlinModule = (Class<? extends Module>)
|
773 |
| - ClassUtils.forName("com.fasterxml.jackson.module.kotlin.KotlinModule", |
774 |
| - this.moduleClassLoader); |
| 771 | + ClassUtils.forName("com.fasterxml.jackson.module.kotlin.KotlinModule", this.moduleClassLoader); |
775 | 772 | objectMapper.registerModule(BeanUtils.instantiateClass(kotlinModule));
|
776 | 773 | }
|
777 | 774 | catch (ClassNotFoundException ex) {
|
778 |
| - logger.warn("For Jackson Kotlin classes support please add " + |
779 |
| - "\"com.fasterxml.jackson.module:jackson-module-kotlin\" to the classpath"); |
| 775 | + if (!kotlinWarningLogged) { |
| 776 | + kotlinWarningLogged = true; |
| 777 | + logger.warn("For Jackson Kotlin classes support please add " + |
| 778 | + "\"com.fasterxml.jackson.module:jackson-module-kotlin\" to the classpath"); |
| 779 | + } |
780 | 780 | }
|
781 | 781 | }
|
782 | 782 | }
|
|
0 commit comments