mirror of
https://github.com/spring-projects/spring-framework.git
synced 2026-09-23 06:29:10 +00:00
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:
+4
-5
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
+4
-5
@@ -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();
|
||||
|
||||
+3
-4
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user