11/*
2- * Copyright 2002-2021 the original author or authors.
2+ * Copyright 2002-2022 the original author or authors.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
@@ -521,7 +521,7 @@ public Jackson2ObjectMapperBuilder featuresToDisable(Object... featuresToDisable
521521 }
522522
523523 /**
524- * Specify one or more modules to be registered with the {@link ObjectMapper}.
524+ * Specify the modules to be registered with the {@link ObjectMapper}.
525525 * <p>Multiple invocations are not additive, the last one defines the modules to
526526 * register.
527527 * <p>Note: If this is set, no finding of modules is going to happen - not by
@@ -538,15 +538,9 @@ public Jackson2ObjectMapperBuilder modules(Module... modules) {
538538 }
539539
540540 /**
541- * Set a complete list of modules to be registered with the {@link ObjectMapper}.
542- * <p>Multiple invocations are not additive, the last one defines the modules to
543- * register.
544- * <p>Note: If this is set, no finding of modules is going to happen - not by
545- * Jackson, and not by Spring either (see {@link #findModulesViaServiceLoader}).
546- * As a consequence, specifying an empty list here will suppress any kind of
547- * module detection.
548- * <p>Specify either this or {@link #modulesToInstall}, not both.
541+ * Variant of {@link #modules(Module...)} with a {@link List}.
549542 * @see #modules(Module...)
543+ * @see #modules(Consumer)
550544 * @see com.fasterxml.jackson.databind.Module
551545 */
552546 public Jackson2ObjectMapperBuilder modules (List <Module > modules ) {
@@ -556,6 +550,22 @@ public Jackson2ObjectMapperBuilder modules(List<Module> modules) {
556550 return this ;
557551 }
558552
553+ /**
554+ * Variant of {@link #modules(Module...)} with a {@link Consumer} for full
555+ * control over the underlying list of modules.
556+ * @since 6.0
557+ * @see #modules(Module...)
558+ * @see #modules(List)
559+ * @see com.fasterxml.jackson.databind.Module
560+ */
561+ public Jackson2ObjectMapperBuilder modules (Consumer <List <Module >> consumer ) {
562+ this .modules = (this .modules != null ? this .modules : new ArrayList <>());
563+ this .findModulesViaServiceLoader = false ;
564+ this .findWellKnownModules = false ;
565+ consumer .accept (this .modules );
566+ return this ;
567+ }
568+
559569 /**
560570 * Specify one or more modules to be registered with the {@link ObjectMapper}.
561571 * <p>Multiple invocations are not additive, the last one defines the modules
@@ -566,6 +576,7 @@ public Jackson2ObjectMapperBuilder modules(List<Module> modules) {
566576 * allowing to eventually override their configuration.
567577 * <p>Specify either this or {@link #modules(Module...)}, not both.
568578 * @since 4.1.5
579+ * @see #modulesToInstall(Consumer)
569580 * @see #modulesToInstall(Class...)
570581 * @see com.fasterxml.jackson.databind.Module
571582 */
@@ -575,6 +586,21 @@ public Jackson2ObjectMapperBuilder modulesToInstall(Module... modules) {
575586 return this ;
576587 }
577588
589+ /**
590+ * Variant of {@link #modulesToInstall(Module...)} with a {@link Consumer}
591+ * for full control over the underlying list of modules.
592+ * @since 6.0
593+ * @see #modulesToInstall(Module...)
594+ * @see #modulesToInstall(Class...)
595+ * @see com.fasterxml.jackson.databind.Module
596+ */
597+ public Jackson2ObjectMapperBuilder modulesToInstall (Consumer <List <Module >> consumer ) {
598+ this .modules = (this .modules != null ? this .modules : new ArrayList <>());
599+ this .findWellKnownModules = true ;
600+ consumer .accept (this .modules );
601+ return this ;
602+ }
603+
578604 /**
579605 * Specify one or more modules by class to be registered with
580606 * the {@link ObjectMapper}.
@@ -586,6 +612,7 @@ public Jackson2ObjectMapperBuilder modulesToInstall(Module... modules) {
586612 * allowing to eventually override their configuration.
587613 * <p>Specify either this or {@link #modules(Module...)}, not both.
588614 * @see #modulesToInstall(Module...)
615+ * @see #modulesToInstall(Consumer)
589616 * @see com.fasterxml.jackson.databind.Module
590617 */
591618 @ SafeVarargs
0 commit comments