Use @SafeVarargs in Jackson builder and factory
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-25311
This commit is contained in:
committed by
Sam Brannen
parent
b33d2fe683
commit
a142d21700
@@ -595,8 +595,8 @@ public class Jackson2ObjectMapperBuilder {
|
||||
* @see #modulesToInstall(Module...)
|
||||
* @see com.fasterxml.jackson.databind.Module
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public Jackson2ObjectMapperBuilder modulesToInstall(Class<? extends Module>... modules) {
|
||||
@SafeVarargs
|
||||
public final Jackson2ObjectMapperBuilder modulesToInstall(Class<? extends Module>... modules) {
|
||||
this.moduleClasses = modules;
|
||||
this.findWellKnownModules = true;
|
||||
return this;
|
||||
|
||||
@@ -409,8 +409,8 @@ public class Jackson2ObjectMapperFactoryBean implements FactoryBean<ObjectMapper
|
||||
* @since 4.0.1
|
||||
* @see com.fasterxml.jackson.databind.Module
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public void setModulesToInstall(Class<? extends Module>... modules) {
|
||||
@SafeVarargs
|
||||
public final void setModulesToInstall(Class<? extends Module>... modules) {
|
||||
this.builder.modulesToInstall(modules);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user