Skip to content

Commit

Permalink
Avoid multiple warnings related to jackson-module-kotlin
Browse files Browse the repository at this point in the history
Issue: SPR-16497
  • Loading branch information
jhoeller committed Feb 14, 2018
1 parent 1aeae5d commit 7baf33f
Showing 1 changed file with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@
*/
public class Jackson2ObjectMapperBuilder {

private static volatile boolean kotlinWarningLogged = false;

private final Log logger = LogFactory.getLog(getClass());

private final Map<Class<?>, Class<?>> mixIns = new HashMap<>();
Expand Down Expand Up @@ -543,7 +545,7 @@ public Jackson2ObjectMapperBuilder modulesToInstall(Class<? extends Module>... m

/**
* Set whether to let Jackson find available modules via the JDK ServiceLoader,
* based on META-INF metadata in the classpath. Requires Jackson 2.2 or higher.
* based on META-INF metadata in the classpath.
* <p>If this mode is not set, Spring's Jackson2ObjectMapperBuilder itself
* will try to find the JSR-310 and Joda-Time support modules on the classpath -
* provided that Java 8 and Joda-Time themselves are available, respectively.
Expand Down Expand Up @@ -616,18 +618,14 @@ 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);
}
objectMapper.registerModules(this.modules);
}
if (this.moduleClasses != null) {
for (Class<? extends Module> module : this.moduleClasses) {
Expand Down Expand Up @@ -770,13 +768,15 @@ private void registerWellKnownModulesIfAvailable(ObjectMapper objectMapper) {
if (KotlinDetector.isKotlinPresent()) {
try {
Class<? extends Module> kotlinModule = (Class<? extends Module>)
ClassUtils.forName("com.fasterxml.jackson.module.kotlin.KotlinModule",
this.moduleClassLoader);
ClassUtils.forName("com.fasterxml.jackson.module.kotlin.KotlinModule", this.moduleClassLoader);
objectMapper.registerModule(BeanUtils.instantiateClass(kotlinModule));
}
catch (ClassNotFoundException ex) {
logger.warn("For Jackson Kotlin classes support please add " +
"\"com.fasterxml.jackson.module:jackson-module-kotlin\" to the classpath");
if (!kotlinWarningLogged) {
kotlinWarningLogged = true;
logger.warn("For Jackson Kotlin classes support please add " +
"\"com.fasterxml.jackson.module:jackson-module-kotlin\" to the classpath");
}
}
}
}
Expand Down

0 comments on commit 7baf33f

Please sign in to comment.