Skip to content

Support adding rather than replacing modules in Jackson2ObjectMapperBuilder #28633

Closed
@AQS-DTheuke

Description

@AQS-DTheuke

public Jackson2ObjectMapperBuilder modulesToInstall(Module... modules) {
this.modules = Arrays.asList(modules);
this.findWellKnownModules = true;
return this;
}

Currently the Jackson2ObjectMapperBuilderCustomizer is only able to replace the modules that should be installed; however, it is possible to define multiple Spring Boot Jackson2ObjectMapperBuilderCustomizer beans that could each wish to add a Jackson module. However the later customizers will always remove the modules configured by the previous instance. It isn't possible to get the current list of modules either and extend that.

We wish to separate our customizers by their related modules/source libraries (api-docs, error-handling, ..., and the application itself).

So it would be nice if there was a addModules(toInstall) method that would add the modules to the list instead of replacing it.

Most of the other methods such as serializers(JsonSerializer<?>...) already work like that:

public Jackson2ObjectMapperBuilder serializers(JsonSerializer<?>... serializers) {
for (JsonSerializer<?> serializer : serializers) {
Class<?> handledType = serializer.handledType();
if (handledType == null || handledType == Object.class) {
throw new IllegalArgumentException("Unknown handled type in " + serializer.getClass().getName());
}
this.serializers.put(serializer.handledType(), serializer);
}
return this;
}

Thanks for your awesome work.

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions