Use JsonMapper instead of ObjectMapper when relevant

This commit updates Jackson 3 support to use JsonMapper instead
of ObjectMapper in converter, codec and view constructors.

Closes gh-35282
This commit is contained in:
Sébastien Deleuze
2025-08-12 10:36:37 +02:00
parent bde806b7fc
commit d115f36400
17 changed files with 94 additions and 105 deletions
@@ -25,7 +25,6 @@ import java.util.Map;
import org.jspecify.annotations.Nullable;
import org.reactivestreams.Publisher;
import reactor.core.publisher.Flux;
import tools.jackson.databind.ObjectMapper;
import tools.jackson.databind.cfg.MapperBuilder;
import tools.jackson.databind.json.JsonMapper;
@@ -73,20 +72,20 @@ public class JacksonJsonDecoder extends AbstractJacksonDecoder {
}
/**
* Construct a new instance with the provided {@link ObjectMapper}.
* Construct a new instance with the provided {@link JsonMapper}.
* @see JsonMapper#builder()
* @see MapperBuilder#findModules(ClassLoader)
*/
public JacksonJsonDecoder(ObjectMapper mapper) {
public JacksonJsonDecoder(JsonMapper mapper) {
this(mapper, DEFAULT_JSON_MIME_TYPES);
}
/**
* Construct a new instance with the provided {@link ObjectMapper} and {@link MimeType}s.
* Construct a new instance with the provided {@link JsonMapper} and {@link MimeType}s.
* @see JsonMapper#builder()
* @see MapperBuilder#findModules(ClassLoader)
*/
public JacksonJsonDecoder(ObjectMapper mapper, MimeType... mimeTypes) {
public JacksonJsonDecoder(JsonMapper mapper, MimeType... mimeTypes) {
super(mapper, mimeTypes);
}
@@ -25,7 +25,6 @@ import reactor.core.publisher.Flux;
import tools.jackson.core.PrettyPrinter;
import tools.jackson.core.util.DefaultIndenter;
import tools.jackson.core.util.DefaultPrettyPrinter;
import tools.jackson.databind.ObjectMapper;
import tools.jackson.databind.ObjectWriter;
import tools.jackson.databind.SerializationFeature;
import tools.jackson.databind.cfg.MapperBuilder;
@@ -80,21 +79,21 @@ public class JacksonJsonEncoder extends AbstractJacksonEncoder {
}
/**
* Construct a new instance with the provided {@link ObjectMapper}.
* Construct a new instance with the provided {@link JsonMapper}.
* @see JsonMapper#builder()
* @see MapperBuilder#findModules(ClassLoader)
*/
public JacksonJsonEncoder(ObjectMapper mapper) {
public JacksonJsonEncoder(JsonMapper mapper) {
this(mapper, DEFAULT_JSON_MIME_TYPES);
}
/**
* Construct a new instance with the provided {@link ObjectMapper} and
* Construct a new instance with the provided {@link JsonMapper} and
* {@link MimeType}s.
* @see JsonMapper#builder()
* @see MapperBuilder#findModules(ClassLoader)
*/
public JacksonJsonEncoder(ObjectMapper mapper, MimeType... mimeTypes) {
public JacksonJsonEncoder(JsonMapper mapper, MimeType... mimeTypes) {
super(mapper, mimeTypes);
setStreamingMediaTypes(List.of(MediaType.APPLICATION_NDJSON));
this.ssePrettyPrinter = initSsePrettyPrinter();
@@ -21,7 +21,6 @@ import java.util.List;
import org.jspecify.annotations.Nullable;
import tools.jackson.core.JsonGenerator;
import tools.jackson.databind.ObjectMapper;
import tools.jackson.databind.cfg.MapperBuilder;
import tools.jackson.databind.json.JsonMapper;
@@ -32,7 +31,7 @@ import org.springframework.http.converter.AbstractJacksonHttpMessageConverter;
/**
* Implementation of {@link org.springframework.http.converter.HttpMessageConverter}
* that can read and write JSON using <a href="https://github.com/FasterXML/jackson">Jackson 3.x's</a>
* {@link ObjectMapper}.
* {@link JsonMapper}.
*
* <p>This converter can be used to bind to typed beans, or untyped
* {@code HashMap} instances.
@@ -79,11 +78,11 @@ public class JacksonJsonHttpMessageConverter extends AbstractJacksonHttpMessageC
}
/**
* Construct a new instance with the provided {@link ObjectMapper}.
* Construct a new instance with the provided {@link JsonMapper}.
* @see JsonMapper#builder()
* @see MapperBuilder#findModules(ClassLoader)
*/
public JacksonJsonHttpMessageConverter(ObjectMapper objectMapper) {
public JacksonJsonHttpMessageConverter(JsonMapper objectMapper) {
super(objectMapper, DEFAULT_JSON_MIME_TYPES);
}