diff --git a/buildSrc/src/main/java/org/springframework/boot/build/AntoraConventions.java b/buildSrc/src/main/java/org/springframework/boot/build/AntoraConventions.java index 7d4fa7eff8d0..cd51d1d1040e 100644 --- a/buildSrc/src/main/java/org/springframework/boot/build/AntoraConventions.java +++ b/buildSrc/src/main/java/org/springframework/boot/build/AntoraConventions.java @@ -41,7 +41,7 @@ import org.gradle.api.tasks.Copy; import org.gradle.api.tasks.TaskContainer; import org.gradle.api.tasks.TaskProvider; -import tools.jackson.databind.ObjectMapper; +import tools.jackson.databind.json.JsonMapper; import org.springframework.boot.build.antora.AntoraAsciidocAttributes; import org.springframework.boot.build.antora.GenerateAntoraPlaybook; @@ -197,8 +197,8 @@ private void logWarningIfNodeModulesInUserHome(Project project) { private String getUiBundleUrl(Project project) { File packageJson = project.getRootProject().file("antora/package.json"); - ObjectMapper objectMapper = new ObjectMapper(); - Map json = objectMapper.readerFor(Map.class).readValue(packageJson); + JsonMapper jsonMapper = new JsonMapper(); + Map json = jsonMapper.readerFor(Map.class).readValue(packageJson); Map config = (json != null) ? (Map) json.get("config") : null; String url = (config != null) ? (String) config.get("ui-bundle-url") : null; Assert.state(StringUtils.hasText(url.toString()), "package.json has not ui-bundle-url config"); diff --git a/buildSrc/src/main/java/org/springframework/boot/build/bom/ResolvedBom.java b/buildSrc/src/main/java/org/springframework/boot/build/bom/ResolvedBom.java index b28f8227361d..7f800014a312 100644 --- a/buildSrc/src/main/java/org/springframework/boot/build/bom/ResolvedBom.java +++ b/buildSrc/src/main/java/org/springframework/boot/build/bom/ResolvedBom.java @@ -25,7 +25,6 @@ import java.util.List; import com.fasterxml.jackson.annotation.JsonInclude.Include; -import tools.jackson.databind.ObjectMapper; import tools.jackson.databind.json.JsonMapper; /** @@ -37,17 +36,17 @@ */ public record ResolvedBom(Id id, List libraries) { - private static final ObjectMapper objectMapper; + private static final JsonMapper jsonMapper; static { - objectMapper = JsonMapper.builder() + jsonMapper = JsonMapper.builder() .changeDefaultPropertyInclusion((value) -> value.withContentInclusion(Include.NON_EMPTY)) .build(); } public static ResolvedBom readFrom(File file) { try (FileReader reader = new FileReader(file)) { - return objectMapper.readValue(reader, ResolvedBom.class); + return jsonMapper.readValue(reader, ResolvedBom.class); } catch (IOException ex) { throw new UncheckedIOException(ex); @@ -55,7 +54,7 @@ public static ResolvedBom readFrom(File file) { } public void writeTo(Writer writer) { - objectMapper.writeValue(writer, this); + jsonMapper.writeValue(writer, this); } public record ResolvedLibrary(String name, String version, String versionProperty, List managedDependencies, diff --git a/buildSrc/src/main/java/org/springframework/boot/build/context/properties/CheckAdditionalSpringConfigurationMetadata.java b/buildSrc/src/main/java/org/springframework/boot/build/context/properties/CheckAdditionalSpringConfigurationMetadata.java index 0d9642fef940..c53c4049c433 100644 --- a/buildSrc/src/main/java/org/springframework/boot/build/context/properties/CheckAdditionalSpringConfigurationMetadata.java +++ b/buildSrc/src/main/java/org/springframework/boot/build/context/properties/CheckAdditionalSpringConfigurationMetadata.java @@ -37,7 +37,7 @@ import org.gradle.api.tasks.SourceTask; import org.gradle.api.tasks.TaskAction; import org.gradle.api.tasks.VerificationException; -import tools.jackson.databind.ObjectMapper; +import tools.jackson.databind.json.JsonMapper; /** * {@link SourceTask} that checks additional Spring configuration metadata files. @@ -75,11 +75,11 @@ void check() throws IOException { @SuppressWarnings("unchecked") private Report createReport() { - ObjectMapper objectMapper = new ObjectMapper(); + JsonMapper jsonMapper = new JsonMapper(); Report report = new Report(); for (File file : getSource().getFiles()) { Analysis analysis = report.analysis(this.projectDir.toPath().relativize(file.toPath())); - Map json = objectMapper.readValue(file, Map.class); + Map json = jsonMapper.readValue(file, Map.class); check("groups", json, analysis); check("properties", json, analysis); check("hints", json, analysis); diff --git a/buildSrc/src/main/java/org/springframework/boot/build/context/properties/CheckSpringConfigurationMetadata.java b/buildSrc/src/main/java/org/springframework/boot/build/context/properties/CheckSpringConfigurationMetadata.java index 7334a96627bf..8c67f6d44605 100644 --- a/buildSrc/src/main/java/org/springframework/boot/build/context/properties/CheckSpringConfigurationMetadata.java +++ b/buildSrc/src/main/java/org/springframework/boot/build/context/properties/CheckSpringConfigurationMetadata.java @@ -37,7 +37,7 @@ import org.gradle.api.tasks.SourceTask; import org.gradle.api.tasks.TaskAction; import org.gradle.api.tasks.VerificationException; -import tools.jackson.databind.ObjectMapper; +import tools.jackson.databind.json.JsonMapper; /** * {@link SourceTask} that checks {@code spring-configuration-metadata.json} files. @@ -75,10 +75,10 @@ void check() throws IOException { @SuppressWarnings("unchecked") private Report createReport() { - ObjectMapper objectMapper = new ObjectMapper(); + JsonMapper jsonMapper = new JsonMapper(); File file = getMetadataLocation().get().getAsFile(); Report report = new Report(this.projectRoot.relativize(file.toPath())); - Map json = objectMapper.readValue(file, Map.class); + Map json = jsonMapper.readValue(file, Map.class); List> properties = (List>) json.get("properties"); for (Map property : properties) { String name = (String) property.get("name"); diff --git a/buildSrc/src/main/java/org/springframework/boot/build/context/properties/ConfigurationProperties.java b/buildSrc/src/main/java/org/springframework/boot/build/context/properties/ConfigurationProperties.java index 55496ef41b72..3755eebd5789 100644 --- a/buildSrc/src/main/java/org/springframework/boot/build/context/properties/ConfigurationProperties.java +++ b/buildSrc/src/main/java/org/springframework/boot/build/context/properties/ConfigurationProperties.java @@ -24,7 +24,7 @@ import java.util.Map; import java.util.stream.Stream; -import tools.jackson.databind.ObjectMapper; +import tools.jackson.databind.json.JsonMapper; /** * Configuration properties read from one or more @@ -55,10 +55,10 @@ Stream stream() { @SuppressWarnings("unchecked") static ConfigurationProperties fromFiles(Iterable files) { - ObjectMapper objectMapper = new ObjectMapper(); + JsonMapper jsonMapper = new JsonMapper(); List properties = new ArrayList<>(); for (File file : files) { - Map json = objectMapper.readValue(file, Map.class); + Map json = jsonMapper.readValue(file, Map.class); for (Map property : (List>) json.get("properties")) { properties.add(ConfigurationProperty.fromJsonProperties(property)); } diff --git a/buildpack/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/type/ImageArchive.java b/buildpack/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/type/ImageArchive.java index 700dc34ab1b7..e0ce2408a6e9 100644 --- a/buildpack/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/type/ImageArchive.java +++ b/buildpack/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/type/ImageArchive.java @@ -31,7 +31,7 @@ import org.jspecify.annotations.Nullable; import tools.jackson.databind.JsonNode; -import tools.jackson.databind.ObjectMapper; +import tools.jackson.databind.json.JsonMapper; import tools.jackson.databind.node.ArrayNode; import tools.jackson.databind.node.ObjectNode; @@ -67,7 +67,7 @@ public class ImageArchive implements TarArchive { private static final IOConsumer NO_UPDATES = (update) -> { }; - private final ObjectMapper objectMapper; + private final JsonMapper jsonMapper; private final ImageConfig imageConfig; @@ -85,10 +85,10 @@ public class ImageArchive implements TarArchive { private final List newLayers; - ImageArchive(ObjectMapper objectMapper, ImageConfig imageConfig, Instant createDate, @Nullable ImageReference tag, + ImageArchive(JsonMapper jsonMapper, ImageConfig imageConfig, Instant createDate, @Nullable ImageReference tag, String os, @Nullable String architecture, @Nullable String variant, List existingLayers, List newLayers) { - this.objectMapper = objectMapper; + this.jsonMapper = jsonMapper; this.imageConfig = imageConfig; this.createDate = createDate; this.tag = tag; @@ -158,7 +158,7 @@ private LayerId writeLayer(Layout writer, Layer layer) throws IOException { private String writeConfig(Layout writer, List writtenLayers) throws IOException { try { ObjectNode config = createConfig(writtenLayers); - String json = this.objectMapper.writeValueAsString(config).replace("\r\n", "\n"); + String json = this.jsonMapper.writeValueAsString(config).replace("\r\n", "\n"); MessageDigest digest = MessageDigest.getInstance("SHA-256"); InspectedContent content = InspectedContent.of(Content.of(json), digest::update); String name = LayerId.ofSha256Digest(digest.digest()).getHash() + ".json"; @@ -171,7 +171,7 @@ private String writeConfig(Layout writer, List writtenLayers) throws IO } private ObjectNode createConfig(List writtenLayers) { - ObjectNode config = this.objectMapper.createObjectNode(); + ObjectNode config = this.jsonMapper.createObjectNode(); config.set("Config", this.imageConfig.getNodeCopy()); config.set("Created", config.stringNode(getCreatedDate())); config.set("History", createHistory(writtenLayers)); @@ -187,7 +187,7 @@ private String getCreatedDate() { } private JsonNode createHistory(List writtenLayers) { - ArrayNode history = this.objectMapper.createArrayNode(); + ArrayNode history = this.jsonMapper.createArrayNode(); int size = this.existingLayers.size() + writtenLayers.size(); for (int i = 0; i < size; i++) { history.addObject(); @@ -196,7 +196,7 @@ private JsonNode createHistory(List writtenLayers) { } private JsonNode createRootFs(List writtenLayers) { - ObjectNode rootFs = this.objectMapper.createObjectNode(); + ObjectNode rootFs = this.jsonMapper.createObjectNode(); ArrayNode diffIds = rootFs.putArray("diff_ids"); this.existingLayers.stream().map(Object::toString).forEach(diffIds::add); writtenLayers.stream().map(Object::toString).forEach(diffIds::add); @@ -205,12 +205,12 @@ private JsonNode createRootFs(List writtenLayers) { private void writeManifest(Layout writer, String config, List writtenLayers) throws IOException { ArrayNode manifest = createManifest(config, writtenLayers); - String manifestJson = this.objectMapper.writeValueAsString(manifest); + String manifestJson = this.jsonMapper.writeValueAsString(manifest); writer.file("manifest.json", Owner.ROOT, Content.of(manifestJson)); } private ArrayNode createManifest(String config, List writtenLayers) { - ArrayNode manifest = this.objectMapper.createArrayNode(); + ArrayNode manifest = this.jsonMapper.createArrayNode(); ObjectNode entry = manifest.addObject(); entry.set("Config", entry.stringNode(config)); entry.set("Layers", getManifestLayers(writtenLayers)); @@ -221,7 +221,7 @@ private ArrayNode createManifest(String config, List writtenLayers) { } private ArrayNode getManifestLayers(List writtenLayers) { - ArrayNode layers = this.objectMapper.createArrayNode(); + ArrayNode layers = this.jsonMapper.createArrayNode(); for (int i = 0; i < this.existingLayers.size(); i++) { layers.add(EMPTY_LAYER_NAME_PREFIX + i); } diff --git a/buildpack/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/json/MappedObject.java b/buildpack/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/json/MappedObject.java index 1ac4b62a2142..992fed9e5117 100644 --- a/buildpack/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/json/MappedObject.java +++ b/buildpack/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/json/MappedObject.java @@ -33,7 +33,6 @@ import org.jspecify.annotations.Nullable; import tools.jackson.core.JacksonException; import tools.jackson.databind.JsonNode; -import tools.jackson.databind.ObjectMapper; import tools.jackson.databind.json.JsonMapper; import org.springframework.util.Assert; @@ -162,7 +161,7 @@ protected static T getRoot(Object proxy) { * @throws IOException on IO error */ protected static T of(String content, Function factory) throws IOException { - return of(content, ObjectMapper::readTree, factory); + return of(content, JsonMapper::readTree, factory); } /** @@ -175,7 +174,7 @@ protected static T of(String content, Function T of(InputStream content, Function factory) throws IOException { - return of(StreamUtils.nonClosing(content), ObjectMapper::readTree, factory); + return of(StreamUtils.nonClosing(content), JsonMapper::readTree, factory); } /** @@ -205,12 +204,12 @@ protected interface ContentReader { /** * Read JSON content as a {@link JsonNode}. - * @param objectMapper the source object mapper + * @param jsonMapper the source json mapper * @param content the content to read * @return a {@link JsonNode} * @throws IOException on IO error */ - JsonNode read(ObjectMapper objectMapper, C content) throws IOException; + JsonNode read(JsonMapper jsonMapper, C content) throws IOException; } diff --git a/core/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/core/DockerJson.java b/core/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/core/DockerJson.java index 3ec245dfc778..97d6e48f0021 100644 --- a/core/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/core/DockerJson.java +++ b/core/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/core/DockerJson.java @@ -22,7 +22,6 @@ import tools.jackson.databind.DeserializationFeature; import tools.jackson.databind.JavaType; import tools.jackson.databind.MapperFeature; -import tools.jackson.databind.ObjectMapper; import tools.jackson.databind.json.JsonMapper; /** @@ -34,7 +33,7 @@ */ final class DockerJson { - private static final ObjectMapper objectMapper = JsonMapper.builder() + private static final JsonMapper jsonMapper = JsonMapper.builder() .defaultLocale(Locale.ENGLISH) .enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES) .disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES) @@ -53,7 +52,7 @@ private DockerJson() { */ static List deserializeToList(String json, Class itemType) { if (json.startsWith("[")) { - JavaType javaType = objectMapper.getTypeFactory().constructCollectionType(List.class, itemType); + JavaType javaType = jsonMapper.getTypeFactory().constructCollectionType(List.class, itemType); return deserialize(json, javaType); } return json.trim().lines().map((line) -> deserialize(line, itemType)).toList(); @@ -67,11 +66,11 @@ static List deserializeToList(String json, Class itemType) { * @return the deserialized result */ static T deserialize(String json, Class type) { - return deserialize(json, objectMapper.getTypeFactory().constructType(type)); + return deserialize(json, jsonMapper.getTypeFactory().constructType(type)); } private static T deserialize(String json, JavaType type) { - return objectMapper.readValue(json.trim(), type); + return jsonMapper.readValue(json.trim(), type); } } diff --git a/core/spring-boot-test/src/main/java/org/springframework/boot/test/json/JacksonTester.java b/core/spring-boot-test/src/main/java/org/springframework/boot/test/json/JacksonTester.java index 94f3ff93779e..1b1b14901065 100644 --- a/core/spring-boot-test/src/main/java/org/springframework/boot/test/json/JacksonTester.java +++ b/core/spring-boot-test/src/main/java/org/springframework/boot/test/json/JacksonTester.java @@ -37,7 +37,6 @@ import tools.jackson.core.JacksonException; import tools.jackson.core.JsonGenerator; import tools.jackson.databind.JavaType; -import tools.jackson.databind.ObjectMapper; import tools.jackson.databind.ObjectReader; import tools.jackson.databind.ObjectWriter; import tools.jackson.databind.json.JsonMapper; @@ -214,13 +213,13 @@ protected AbstractJsonMarshalTester createTester(Class resourceLoadCl private static final class JacksonJsonProvider extends AbstractJsonProvider { - private final ObjectMapper objectMapper; + private final JsonMapper jsonMapper; private final ObjectReader objectReader; - private JacksonJsonProvider(ObjectMapper objectMapper) { - this.objectMapper = objectMapper; - this.objectReader = objectMapper.reader().forType(Object.class); + private JacksonJsonProvider(JsonMapper jsonMapper) { + this.jsonMapper = jsonMapper; + this.objectReader = jsonMapper.reader().forType(Object.class); } @Override @@ -256,8 +255,8 @@ public Object parse(InputStream jsonStream, String charset) throws InvalidJsonEx @Override public String toJson(Object obj) { StringWriter writer = new StringWriter(); - try (JsonGenerator generator = this.objectMapper.createGenerator(writer)) { - this.objectMapper.writeValue(generator, obj); + try (JsonGenerator generator = this.jsonMapper.createGenerator(writer)) { + this.jsonMapper.writeValue(generator, obj); } catch (JacksonException ex) { throw new InvalidJsonException(ex); @@ -279,10 +278,10 @@ public Object createMap() { private static final class JacksonMappingProvider implements MappingProvider { - private final ObjectMapper objectMapper; + private final JsonMapper jsonMapper; - private JacksonMappingProvider(ObjectMapper objectMapper) { - this.objectMapper = objectMapper; + private JacksonMappingProvider(JsonMapper jsonMapper) { + this.jsonMapper = jsonMapper; } @Override @@ -291,7 +290,7 @@ private JacksonMappingProvider(ObjectMapper objectMapper) { return null; } try { - return this.objectMapper.convertValue(source, targetType); + return this.jsonMapper.convertValue(source, targetType); } catch (Exception ex) { throw new MappingException(ex); @@ -305,9 +304,9 @@ private JacksonMappingProvider(ObjectMapper objectMapper) { if (source == null) { return null; } - JavaType type = this.objectMapper.getTypeFactory().constructType(targetType.getType()); + JavaType type = this.jsonMapper.getTypeFactory().constructType(targetType.getType()); try { - return (T) this.objectMapper.convertValue(source, type); + return (T) this.jsonMapper.convertValue(source, type); } catch (Exception ex) { throw new MappingException(ex); diff --git a/core/spring-boot/src/main/java/org/springframework/boot/json/JacksonJsonParser.java b/core/spring-boot/src/main/java/org/springframework/boot/json/JacksonJsonParser.java index c41437d74529..b50a6cfe4eea 100644 --- a/core/spring-boot/src/main/java/org/springframework/boot/json/JacksonJsonParser.java +++ b/core/spring-boot/src/main/java/org/springframework/boot/json/JacksonJsonParser.java @@ -24,7 +24,7 @@ import tools.jackson.databind.ObjectMapper; /** - * Thin wrapper to adapt Jackson 2 {@link ObjectMapper} to {@link JsonParser}. + * Thin wrapper to adapt Jackson 3 {@link ObjectMapper} to {@link JsonParser}. * * @author Dave Syer * @since 1.0.0 diff --git a/core/spring-boot/src/test/java/org/springframework/boot/logging/log4j2/AbstractStructuredLoggingTests.java b/core/spring-boot/src/test/java/org/springframework/boot/logging/log4j2/AbstractStructuredLoggingTests.java index 81d6118e8ed9..1e9212faca13 100644 --- a/core/spring-boot/src/test/java/org/springframework/boot/logging/log4j2/AbstractStructuredLoggingTests.java +++ b/core/spring-boot/src/test/java/org/springframework/boot/logging/log4j2/AbstractStructuredLoggingTests.java @@ -28,7 +28,7 @@ import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import tools.jackson.core.type.TypeReference; -import tools.jackson.databind.ObjectMapper; +import tools.jackson.databind.json.JsonMapper; import org.springframework.boot.logging.structured.MockStructuredLoggingJsonMembersCustomizerBuilder; import org.springframework.boot.logging.structured.StructuredLoggingJsonMembersCustomizer; @@ -45,7 +45,7 @@ abstract class AbstractStructuredLoggingTests { static final Instant EVENT_TIME = Instant.ofEpochMilli(1719910193000L); - private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); + private static final JsonMapper JSON_MAPPER = new JsonMapper(); @Mock @SuppressWarnings("NullAway.Init") @@ -79,7 +79,7 @@ protected static MutableLogEvent createEvent(@Nullable Throwable thrown) { } protected Map deserialize(String json) { - return OBJECT_MAPPER.readValue(json, new TypeReference<>() { + return JSON_MAPPER.readValue(json, new TypeReference<>() { }); } diff --git a/core/spring-boot/src/test/java/org/springframework/boot/logging/logback/AbstractStructuredLoggingTests.java b/core/spring-boot/src/test/java/org/springframework/boot/logging/logback/AbstractStructuredLoggingTests.java index fc806a1b63bf..d6f4ae79b1a1 100644 --- a/core/spring-boot/src/test/java/org/springframework/boot/logging/logback/AbstractStructuredLoggingTests.java +++ b/core/spring-boot/src/test/java/org/springframework/boot/logging/logback/AbstractStructuredLoggingTests.java @@ -36,7 +36,7 @@ import org.slf4j.event.KeyValuePair; import org.slf4j.helpers.BasicMarkerFactory; import tools.jackson.core.type.TypeReference; -import tools.jackson.databind.ObjectMapper; +import tools.jackson.databind.json.JsonMapper; import org.springframework.boot.logging.structured.MockStructuredLoggingJsonMembersCustomizerBuilder; import org.springframework.boot.logging.structured.StructuredLoggingJsonMembersCustomizer; @@ -53,7 +53,7 @@ abstract class AbstractStructuredLoggingTests { static final Instant EVENT_TIME = Instant.ofEpochSecond(1719910193L); - private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); + private static final JsonMapper JSON_MAPPER = new JsonMapper(); private ThrowableProxyConverter throwableProxyConverter; @@ -122,7 +122,7 @@ protected static LoggingEvent createEvent(@Nullable Throwable thrown) { } protected Map deserialize(String json) { - return OBJECT_MAPPER.readValue(json, new TypeReference<>() { + return JSON_MAPPER.readValue(json, new TypeReference<>() { }); } diff --git a/documentation/spring-boot-actuator-docs/src/test/java/org/springframework/boot/actuate/docs/AbstractEndpointDocumentationTests.java b/documentation/spring-boot-actuator-docs/src/test/java/org/springframework/boot/actuate/docs/AbstractEndpointDocumentationTests.java index db8036e89c6d..da36b8926cfe 100644 --- a/documentation/spring-boot-actuator-docs/src/test/java/org/springframework/boot/actuate/docs/AbstractEndpointDocumentationTests.java +++ b/documentation/spring-boot-actuator-docs/src/test/java/org/springframework/boot/actuate/docs/AbstractEndpointDocumentationTests.java @@ -76,8 +76,8 @@ protected OperationPreprocessor limit(String... keys) { @SuppressWarnings("unchecked") protected OperationPreprocessor limit(Predicate filter, String... keys) { return new ContentModifyingOperationPreprocessor((content, mediaType) -> { - JsonMapper objectMapper = JsonMapper.builder().enable(SerializationFeature.INDENT_OUTPUT).build(); - Map payload = objectMapper.readValue(content, Map.class); + JsonMapper jsonMapper = JsonMapper.builder().enable(SerializationFeature.INDENT_OUTPUT).build(); + Map payload = jsonMapper.readValue(content, Map.class); Object target = payload; Map parent = null; for (String key : keys) { @@ -93,7 +93,7 @@ protected OperationPreprocessor limit(Predicate filter, String... keys) { else { parent.put(keys[keys.length - 1], select((List) target, filter)); } - return objectMapper.writeValueAsBytes(payload); + return jsonMapper.writeValueAsBytes(payload); }); } diff --git a/documentation/spring-boot-actuator-docs/src/test/java/org/springframework/boot/actuate/docs/env/EnvironmentEndpointDocumentationTests.java b/documentation/spring-boot-actuator-docs/src/test/java/org/springframework/boot/actuate/docs/env/EnvironmentEndpointDocumentationTests.java index 7406b6d8c6ae..b537e74fd7c7 100644 --- a/documentation/spring-boot-actuator-docs/src/test/java/org/springframework/boot/actuate/docs/env/EnvironmentEndpointDocumentationTests.java +++ b/documentation/spring-boot-actuator-docs/src/test/java/org/springframework/boot/actuate/docs/env/EnvironmentEndpointDocumentationTests.java @@ -24,7 +24,6 @@ import java.util.stream.Collectors; import org.junit.jupiter.api.Test; -import tools.jackson.databind.ObjectMapper; import tools.jackson.databind.SerializationFeature; import tools.jackson.databind.json.JsonMapper; @@ -116,8 +115,8 @@ private OperationPreprocessor filterProperties() { @SuppressWarnings("unchecked") private byte[] filterProperties(byte[] content, MediaType mediaType) { - ObjectMapper objectMapper = JsonMapper.builder().enable(SerializationFeature.INDENT_OUTPUT).build(); - Map payload = objectMapper.readValue(content, Map.class); + JsonMapper jsonMapper = JsonMapper.builder().enable(SerializationFeature.INDENT_OUTPUT).build(); + Map payload = jsonMapper.readValue(content, Map.class); List> propertySources = (List>) payload.get("propertySources"); for (Map propertySource : propertySources) { Map properties = (Map) propertySource.get("properties"); @@ -128,7 +127,7 @@ private byte[] filterProperties(byte[] content, MediaType mediaType) { .collect(Collectors.toSet()); properties.keySet().retainAll(filteredKeys); } - return objectMapper.writeValueAsBytes(payload); + return jsonMapper.writeValueAsBytes(payload); } private boolean retainKey(String key) { diff --git a/integration-test/spring-boot-actuator-integration-tests/src/test/java/org/springframework/boot/actuate/metrics/MetricsEndpointWebIntegrationTests.java b/integration-test/spring-boot-actuator-integration-tests/src/test/java/org/springframework/boot/actuate/metrics/MetricsEndpointWebIntegrationTests.java index 9bc8516634fb..5c18f68fcd33 100644 --- a/integration-test/spring-boot-actuator-integration-tests/src/test/java/org/springframework/boot/actuate/metrics/MetricsEndpointWebIntegrationTests.java +++ b/integration-test/spring-boot-actuator-integration-tests/src/test/java/org/springframework/boot/actuate/metrics/MetricsEndpointWebIntegrationTests.java @@ -24,7 +24,7 @@ import io.micrometer.core.instrument.binder.jvm.JvmMemoryMetrics; import io.micrometer.core.instrument.simple.SimpleConfig; import io.micrometer.core.instrument.simple.SimpleMeterRegistry; -import tools.jackson.databind.ObjectMapper; +import tools.jackson.databind.json.JsonMapper; import org.springframework.boot.actuate.endpoint.web.test.WebEndpointTest; import org.springframework.boot.micrometer.metrics.actuate.endpoint.MetricsEndpoint; @@ -44,7 +44,7 @@ class MetricsEndpointWebIntegrationTests { private static final MeterRegistry registry = new SimpleMeterRegistry(SimpleConfig.DEFAULT, new MockClock()); - private final ObjectMapper mapper = new ObjectMapper(); + private final JsonMapper mapper = new JsonMapper(); @WebEndpointTest @SuppressWarnings("unchecked") diff --git a/module/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/context/properties/ConfigurationPropertiesReportEndpoint.java b/module/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/context/properties/ConfigurationPropertiesReportEndpoint.java index 051df4265223..bb7a08ce808e 100644 --- a/module/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/context/properties/ConfigurationPropertiesReportEndpoint.java +++ b/module/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/context/properties/ConfigurationPropertiesReportEndpoint.java @@ -34,7 +34,6 @@ import org.jspecify.annotations.Nullable; import tools.jackson.core.JsonGenerator; import tools.jackson.databind.BeanDescription; -import tools.jackson.databind.ObjectMapper; import tools.jackson.databind.SerializationConfig; import tools.jackson.databind.SerializationContext; import tools.jackson.databind.SerializationFeature; @@ -116,7 +115,7 @@ public class ConfigurationPropertiesReportEndpoint implements ApplicationContext @SuppressWarnings("NullAway.Init") private ApplicationContext context; - private @Nullable ObjectMapper objectMapper; + private @Nullable JsonMapper jsonMapper; public ConfigurationPropertiesReportEndpoint(Iterable sanitizingFunctions, Show showValues) { this.sanitizer = new Sanitizer(sanitizingFunctions); @@ -151,7 +150,7 @@ ConfigurationPropertiesDescriptor getConfigurationProperties(String prefix, bool private ConfigurationPropertiesDescriptor getConfigurationProperties(ApplicationContext context, Predicate beanFilterPredicate, boolean showUnsanitized) { - ObjectMapper mapper = getObjectMapper(); + JsonMapper mapper = getJsonMapper(); Map<@Nullable String, ContextConfigurationPropertiesDescriptor> contexts = new HashMap<>(); ApplicationContext target = context; @@ -162,13 +161,13 @@ private ConfigurationPropertiesDescriptor getConfigurationProperties(Application return new ConfigurationPropertiesDescriptor(contexts); } - private ObjectMapper getObjectMapper() { - if (this.objectMapper == null) { + private JsonMapper getJsonMapper() { + if (this.jsonMapper == null) { JsonMapper.Builder builder = JsonMapper.builder(); configureJsonMapper(builder); - this.objectMapper = builder.build(); + this.jsonMapper = builder.build(); } - return this.objectMapper; + return this.jsonMapper; } /** @@ -203,7 +202,7 @@ private void applySerializationModifier(JsonMapper.Builder builder) { builder.serializerFactory(factory); } - private ContextConfigurationPropertiesDescriptor describeBeans(ObjectMapper mapper, ApplicationContext context, + private ContextConfigurationPropertiesDescriptor describeBeans(JsonMapper mapper, ApplicationContext context, Predicate beanFilterPredicate, boolean showUnsanitized) { Map beans = ConfigurationPropertiesBean.getAll(context); Map descriptors = beans.values() @@ -215,7 +214,7 @@ private ContextConfigurationPropertiesDescriptor describeBeans(ObjectMapper mapp (context.getParent() != null) ? context.getParent().getId() : null); } - private ConfigurationPropertiesBeanDescriptor describeBean(ObjectMapper mapper, ConfigurationPropertiesBean bean, + private ConfigurationPropertiesBeanDescriptor describeBean(JsonMapper mapper, ConfigurationPropertiesBean bean, boolean showUnsanitized) { String prefix = bean.getAnnotation().prefix(); Map serialized = safeSerialize(mapper, bean.getInstance(), prefix); @@ -233,7 +232,7 @@ private ConfigurationPropertiesBeanDescriptor describeBean(ObjectMapper mapper, * @return the serialized instance */ @SuppressWarnings({ "unchecked" }) - private Map safeSerialize(ObjectMapper mapper, @Nullable Object bean, String prefix) { + private Map safeSerialize(JsonMapper mapper, @Nullable Object bean, String prefix) { try { return new HashMap<>(mapper.convertValue(bean, Map.class)); } diff --git a/module/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/CompositeHealthDescriptorTests.java b/module/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/CompositeHealthDescriptorTests.java index 560408aee0bc..8f33525787fb 100644 --- a/module/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/CompositeHealthDescriptorTests.java +++ b/module/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/CompositeHealthDescriptorTests.java @@ -22,7 +22,6 @@ import org.junit.jupiter.api.Test; import tools.jackson.databind.MapperFeature; -import tools.jackson.databind.ObjectMapper; import tools.jackson.databind.json.JsonMapper; import org.springframework.boot.actuate.endpoint.ApiVersion; @@ -76,7 +75,7 @@ void serializeV3WithJacksonReturnsValidJson() throws Exception { components.put("db1", new IndicatedHealthDescriptor(Health.up().build())); components.put("db2", new IndicatedHealthDescriptor(Health.down().withDetail("a", "b").build())); CompositeHealthDescriptor descriptor = new CompositeHealthDescriptor(ApiVersion.V3, Status.UP, components); - ObjectMapper mapper = JsonMapper.builder().enable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY).build(); + JsonMapper mapper = JsonMapper.builder().enable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY).build(); String json = mapper.writeValueAsString(descriptor); assertThat(json).isEqualTo(""" {"components":{"db1":{"status":"UP"},"db2":{"details":{"a":"b"},"status":"DOWN"}},"status":"UP"}"""); @@ -88,7 +87,7 @@ void serializeV2WithJacksonReturnsValidJson() throws Exception { components.put("db1", new IndicatedHealthDescriptor(Health.up().build())); components.put("db2", new IndicatedHealthDescriptor(Health.down().withDetail("a", "b").build())); CompositeHealthDescriptor descriptor = new CompositeHealthDescriptor(ApiVersion.V2, Status.UP, components); - ObjectMapper mapper = JsonMapper.builder().enable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY).build(); + JsonMapper mapper = JsonMapper.builder().enable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY).build(); String json = mapper.writeValueAsString(descriptor); assertThat(json).isEqualTo(""" {"details":{"db1":{"status":"UP"},"db2":{"details":{"a":"b"},"status":"DOWN"}},"status":"UP"}"""); diff --git a/module/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/IndicatedHealthDescriptorTests.java b/module/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/IndicatedHealthDescriptorTests.java index 8a4b7085b5ea..eb1ae63eb862 100644 --- a/module/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/IndicatedHealthDescriptorTests.java +++ b/module/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/IndicatedHealthDescriptorTests.java @@ -18,7 +18,6 @@ import org.junit.jupiter.api.Test; import tools.jackson.databind.MapperFeature; -import tools.jackson.databind.ObjectMapper; import tools.jackson.databind.json.JsonMapper; import org.springframework.boot.health.contributor.Health; @@ -36,7 +35,7 @@ class IndicatedHealthDescriptorTests { void serializeWithJacksonReturnsValidJson() throws Exception { IndicatedHealthDescriptor descriptor = new IndicatedHealthDescriptor( Health.outOfService().withDetail("spring", "boot").build()); - ObjectMapper mapper = JsonMapper.builder().enable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY).build(); + JsonMapper mapper = JsonMapper.builder().enable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY).build(); String json = mapper.writeValueAsString(descriptor); assertThat(json).isEqualTo(""" {"details":{"spring":"boot"},"status":"OUT_OF_SERVICE"}"""); @@ -45,7 +44,7 @@ void serializeWithJacksonReturnsValidJson() throws Exception { @Test void serializeWithJacksonWhenEmptyDetailsReturnsValidJson() throws Exception { IndicatedHealthDescriptor descriptor = new IndicatedHealthDescriptor(Health.outOfService().build()); - ObjectMapper mapper = JsonMapper.builder().enable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY).build(); + JsonMapper mapper = JsonMapper.builder().enable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY).build(); String json = mapper.writeValueAsString(descriptor); assertThat(json).isEqualTo(""" {"status":"OUT_OF_SERVICE"}"""); diff --git a/module/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/SystemHealthDescriptorTests.java b/module/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/SystemHealthDescriptorTests.java index 8e14dbd34303..e050c91e4f0d 100644 --- a/module/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/SystemHealthDescriptorTests.java +++ b/module/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/SystemHealthDescriptorTests.java @@ -24,7 +24,6 @@ import org.junit.jupiter.api.Test; import tools.jackson.databind.MapperFeature; -import tools.jackson.databind.ObjectMapper; import tools.jackson.databind.json.JsonMapper; import org.springframework.boot.actuate.endpoint.ApiVersion; @@ -47,7 +46,7 @@ void serializeWithJacksonReturnsValidJson() throws Exception { components.put("db2", new IndicatedHealthDescriptor(Health.down().withDetail("a", "b").build())); Set groups = new LinkedHashSet<>(Arrays.asList("liveness", "readiness")); SystemHealthDescriptor descriptor = new SystemHealthDescriptor(ApiVersion.V3, Status.UP, components, groups); - ObjectMapper mapper = JsonMapper.builder().enable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY).build(); + JsonMapper mapper = JsonMapper.builder().enable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY).build(); String json = mapper.writeValueAsString(descriptor); assertThat(json).isEqualTo( """ @@ -60,7 +59,7 @@ void serializeWhenNoGroupsWithJacksonReturnsValidJson() throws Exception { components.put("db1", new IndicatedHealthDescriptor(Health.up().build())); components.put("db2", new IndicatedHealthDescriptor(Health.down().withDetail("a", "b").build())); SystemHealthDescriptor descriptor = new SystemHealthDescriptor(ApiVersion.V3, Status.UP, components, null); - ObjectMapper mapper = JsonMapper.builder().enable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY).build(); + JsonMapper mapper = JsonMapper.builder().enable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY).build(); String json = mapper.writeValueAsString(descriptor); assertThat(json).isEqualTo(""" {"components":{"db1":{"status":"UP"},"db2":{"details":{"a":"b"},"status":"DOWN"}},"status":"UP"}"""); @@ -72,7 +71,7 @@ void serializeV2WithJacksonAndDisabledCanOverrideAccessModifiersReturnsValidJson components.put("db1", new IndicatedHealthDescriptor(Health.up().build())); components.put("db2", new IndicatedHealthDescriptor(Health.down().withDetail("a", "b").build())); SystemHealthDescriptor descriptor = new SystemHealthDescriptor(ApiVersion.V2, Status.UP, components, null); - ObjectMapper mapper = JsonMapper.builder() + JsonMapper mapper = JsonMapper.builder() .enable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY) .disable(MapperFeature.CAN_OVERRIDE_ACCESS_MODIFIERS) .build(); diff --git a/module/spring-boot-health/src/test/java/org/springframework/boot/health/contributor/HealthTests.java b/module/spring-boot-health/src/test/java/org/springframework/boot/health/contributor/HealthTests.java index 258e1c9b8e26..86d9db6c9316 100644 --- a/module/spring-boot-health/src/test/java/org/springframework/boot/health/contributor/HealthTests.java +++ b/module/spring-boot-health/src/test/java/org/springframework/boot/health/contributor/HealthTests.java @@ -21,7 +21,7 @@ import java.util.Map; import org.junit.jupiter.api.Test; -import tools.jackson.databind.ObjectMapper; +import tools.jackson.databind.json.JsonMapper; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; @@ -182,7 +182,7 @@ void status() { @Test void serializeWithJacksonReturnsValidJson() throws Exception { Health health = Health.down().withDetail("a", "b").build(); - ObjectMapper mapper = new ObjectMapper(); + JsonMapper mapper = new JsonMapper(); String json = mapper.writeValueAsString(health); assertThat(json).isEqualTo("{\"details\":{\"a\":\"b\"},\"status\":\"DOWN\"}"); } diff --git a/module/spring-boot-health/src/test/java/org/springframework/boot/health/contributor/StatusTests.java b/module/spring-boot-health/src/test/java/org/springframework/boot/health/contributor/StatusTests.java index 2e8c6921aab0..f252f567b4ea 100644 --- a/module/spring-boot-health/src/test/java/org/springframework/boot/health/contributor/StatusTests.java +++ b/module/spring-boot-health/src/test/java/org/springframework/boot/health/contributor/StatusTests.java @@ -17,7 +17,7 @@ package org.springframework.boot.health.contributor; import org.junit.jupiter.api.Test; -import tools.jackson.databind.ObjectMapper; +import tools.jackson.databind.json.JsonMapper; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; @@ -72,7 +72,7 @@ void toStringReturnsCode() { @Test void serializeWithJacksonReturnsValidJson() throws Exception { Status status = new Status("spring", "boot"); - ObjectMapper mapper = new ObjectMapper(); + JsonMapper mapper = new JsonMapper(); String json = mapper.writeValueAsString(status); assertThat(json).isEqualTo("{\"description\":\"boot\",\"status\":\"spring\"}"); } diff --git a/module/spring-boot-jackson/src/test/java/org/springframework/boot/jackson/ObjectValueDeserializerTests.java b/module/spring-boot-jackson/src/test/java/org/springframework/boot/jackson/ObjectValueDeserializerTests.java index c333127bcd0a..f99618f7c720 100644 --- a/module/spring-boot-jackson/src/test/java/org/springframework/boot/jackson/ObjectValueDeserializerTests.java +++ b/module/spring-boot-jackson/src/test/java/org/springframework/boot/jackson/ObjectValueDeserializerTests.java @@ -27,7 +27,6 @@ import tools.jackson.core.JsonParser; import tools.jackson.databind.DeserializationContext; import tools.jackson.databind.JsonNode; -import tools.jackson.databind.ObjectMapper; import tools.jackson.databind.json.JsonMapper; import tools.jackson.databind.module.SimpleModule; import tools.jackson.databind.node.NullNode; @@ -55,7 +54,7 @@ void deserializeObjectShouldReadJson() throws Exception { Deserializer deserializer = new NameAndAgeJsonComponent.Deserializer(); SimpleModule module = new SimpleModule(); module.addDeserializer(NameAndAge.class, deserializer); - ObjectMapper mapper = JsonMapper.builder().addModule(module).build(); + JsonMapper mapper = JsonMapper.builder().addModule(module).build(); NameAndAge nameAndAge = mapper.readValue("{\"name\":\"spring\",\"age\":100}", NameAndAge.class); assertThat(nameAndAge.getName()).isEqualTo("spring"); assertThat(nameAndAge.getAge()).isEqualTo(100); diff --git a/module/spring-boot-jackson/src/test/java/org/springframework/boot/jackson/autoconfigure/JacksonAutoConfigurationTests.java b/module/spring-boot-jackson/src/test/java/org/springframework/boot/jackson/autoconfigure/JacksonAutoConfigurationTests.java index 41451bdd9eaf..eda78882585b 100644 --- a/module/spring-boot-jackson/src/test/java/org/springframework/boot/jackson/autoconfigure/JacksonAutoConfigurationTests.java +++ b/module/spring-boot-jackson/src/test/java/org/springframework/boot/jackson/autoconfigure/JacksonAutoConfigurationTests.java @@ -371,8 +371,8 @@ void customModulesRegisteredByBuilderCustomizerShouldBeRetained() { @Test void defaultSerializationInclusion() { this.contextRunner.run((context) -> { - ObjectMapper objectMapper = context.getBean(JsonMapper.Builder.class).build(); - assertThat(objectMapper.serializationConfig().getDefaultPropertyInclusion().getValueInclusion()) + JsonMapper jsonMapper = context.getBean(JsonMapper.Builder.class).build(); + assertThat(jsonMapper.serializationConfig().getDefaultPropertyInclusion().getValueInclusion()) .isEqualTo(JsonInclude.Include.USE_DEFAULTS); }); } @@ -380,8 +380,8 @@ void defaultSerializationInclusion() { @Test void customSerializationInclusion() { this.contextRunner.withPropertyValues("spring.jackson.default-property-inclusion:non_null").run((context) -> { - ObjectMapper objectMapper = context.getBean(JsonMapper.Builder.class).build(); - assertThat(objectMapper.serializationConfig().getDefaultPropertyInclusion().getValueInclusion()) + JsonMapper jsonMapper = context.getBean(JsonMapper.Builder.class).build(); + assertThat(jsonMapper.serializationConfig().getDefaultPropertyInclusion().getValueInclusion()) .isEqualTo(JsonInclude.Include.NON_NULL); }); } @@ -390,9 +390,9 @@ void customSerializationInclusion() { void customTimeZoneFormattingADate() { this.contextRunner.withPropertyValues("spring.jackson.time-zone:GMT+10", "spring.jackson.date-format:z") .run((context) -> { - ObjectMapper objectMapper = context.getBean(JsonMapper.Builder.class).build(); + JsonMapper jsonMapper = context.getBean(JsonMapper.Builder.class).build(); Date date = new Date(1436966242231L); - assertThat(objectMapper.writeValueAsString(date)).isEqualTo("\"GMT+10:00\""); + assertThat(jsonMapper.writeValueAsString(date)).isEqualTo("\"GMT+10:00\""); }); }