1
1
/*
2
- * Copyright 2002-2021 the original author or authors.
2
+ * Copyright 2002-2022 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -521,7 +521,7 @@ public Jackson2ObjectMapperBuilder featuresToDisable(Object... featuresToDisable
521
521
}
522
522
523
523
/**
524
- * Specify one or more modules to be registered with the {@link ObjectMapper}.
524
+ * Specify the modules to be registered with the {@link ObjectMapper}.
525
525
* <p>Multiple invocations are not additive, the last one defines the modules to
526
526
* register.
527
527
* <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) {
538
538
}
539
539
540
540
/**
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}.
549
542
* @see #modules(Module...)
543
+ * @see #modules(Consumer)
550
544
* @see com.fasterxml.jackson.databind.Module
551
545
*/
552
546
public Jackson2ObjectMapperBuilder modules (List <Module > modules ) {
@@ -556,6 +550,22 @@ public Jackson2ObjectMapperBuilder modules(List<Module> modules) {
556
550
return this ;
557
551
}
558
552
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
+
559
569
/**
560
570
* Specify one or more modules to be registered with the {@link ObjectMapper}.
561
571
* <p>Multiple invocations are not additive, the last one defines the modules
@@ -566,6 +576,7 @@ public Jackson2ObjectMapperBuilder modules(List<Module> modules) {
566
576
* allowing to eventually override their configuration.
567
577
* <p>Specify either this or {@link #modules(Module...)}, not both.
568
578
* @since 4.1.5
579
+ * @see #modulesToInstall(Consumer)
569
580
* @see #modulesToInstall(Class...)
570
581
* @see com.fasterxml.jackson.databind.Module
571
582
*/
@@ -575,6 +586,21 @@ public Jackson2ObjectMapperBuilder modulesToInstall(Module... modules) {
575
586
return this ;
576
587
}
577
588
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
+
578
604
/**
579
605
* Specify one or more modules by class to be registered with
580
606
* the {@link ObjectMapper}.
@@ -586,6 +612,7 @@ public Jackson2ObjectMapperBuilder modulesToInstall(Module... modules) {
586
612
* allowing to eventually override their configuration.
587
613
* <p>Specify either this or {@link #modules(Module...)}, not both.
588
614
* @see #modulesToInstall(Module...)
615
+ * @see #modulesToInstall(Consumer)
589
616
* @see com.fasterxml.jackson.databind.Module
590
617
*/
591
618
@ SafeVarargs
0 commit comments