Using @SafeVarargs in Jackson mapper builder and factory bean classes allows the varargs methods to be used without a compiler warning. The implementations of these methods do not perform unsafe operations on their varargs parameter. It is therefore safe to add this annotation.

The following two methods are changed:

  • add @SafeVarargs to Jackson2ObjectMapperBuilder#modulesToInstall and make it final
  • add @SafeVarargs to Jackson2ObjectMapperFactoryBean#setModulesToInstall and make it final

This is a backwards incompatible change as these methods now have to be declared final. Existing subclasses that override one of these methods will break.

Closes gh-25293

Comment From: sbrannen

When running the Gradle build, it fails with the following:

> Task :spring-web:compileJava FAILED
/Users/XXX/spring-framework/spring-web/src/main/java/org/springframework/http/converter/json/Jackson2ObjectMapperBuilder.java:601: warning: [varargs] Varargs method could cause heap pollution from non-reifiable varargs parameter modules
                this.moduleClasses = modules;

But I'll sort it out. 😉

Comment From: sbrannen

This has been merged into master.

Thanks

Comment From: marschall

Thank you!