From 0ad4fcaeaf27e1690581ee6f6c650d3d88735888 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Deleuze?= Date: Tue, 13 May 2025 12:59:10 +0200 Subject: [PATCH] Update spring-test tests to use Jackson 3 See gh-33798 --- spring-test/spring-test.gradle | 1 + .../HttpMessageContentConverterTests.java | 8 +-- .../json/AbstractJsonContentAssertTests.java | 17 ++---- .../test/json/JsonPathValueAssertTests.java | 8 +-- .../util/JsonPathExpectationsHelperTests.java | 60 +++++++++++++++++-- ...ontentRequestMatchersIntegrationTests.java | 6 +- ...HeaderRequestMatchersIntegrationTests.java | 6 +- ...onPathRequestMatchersIntegrationTests.java | 6 +- .../EncoderDecoderMappingProviderTests.java | 10 ++-- .../server/JsonEncoderDecoderTests.java | 16 ++--- .../servlet/assertj/MockMvcTesterTests.java | 14 ++--- .../client/standalone/FilterTests.java | 4 +- .../samples/context/JavaConfigTests.java | 4 +- .../samples/standalone/AsyncTests.java | 22 +++---- .../samples/standalone/FilterTests.java | 6 +- .../standalone/ViewResolutionTests.java | 3 +- .../setup/StandaloneMockMvcBuilderTests.java | 12 ++-- 17 files changed, 122 insertions(+), 81 deletions(-) diff --git a/spring-test/spring-test.gradle b/spring-test/spring-test.gradle index 6b6ab8709d..4742c72356 100644 --- a/spring-test/spring-test.gradle +++ b/spring-test/spring-test.gradle @@ -81,6 +81,7 @@ dependencies { testImplementation("org.hibernate.validator:hibernate-validator") testImplementation("org.hsqldb:hsqldb") testImplementation("org.junit.platform:junit-platform-testkit") + testImplementation("tools.jackson.core:jackson-databind") testRuntimeOnly("com.sun.xml.bind:jaxb-core") testRuntimeOnly("com.sun.xml.bind:jaxb-impl") testRuntimeOnly("org.glassfish:jakarta.el") diff --git a/spring-test/src/test/java/org/springframework/test/http/HttpMessageContentConverterTests.java b/spring-test/src/test/java/org/springframework/test/http/HttpMessageContentConverterTests.java index 6873a2d341..38cbe93458 100644 --- a/spring-test/src/test/java/org/springframework/test/http/HttpMessageContentConverterTests.java +++ b/spring-test/src/test/java/org/springframework/test/http/HttpMessageContentConverterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2024 the original author or authors. + * Copyright 2002-2025 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,7 +20,6 @@ import java.io.IOException; import java.nio.charset.StandardCharsets; import java.util.List; -import com.fasterxml.jackson.databind.ObjectMapper; import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; @@ -30,7 +29,7 @@ import org.springframework.http.MediaType; import org.springframework.http.converter.GenericHttpMessageConverter; import org.springframework.http.converter.HttpMessageConverter; import org.springframework.http.converter.SmartHttpMessageConverter; -import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; +import org.springframework.http.converter.json.JacksonJsonHttpMessageConverter; import org.springframework.mock.http.MockHttpInputMessage; import org.springframework.mock.http.MockHttpOutputMessage; import org.springframework.util.StreamUtils; @@ -57,8 +56,7 @@ class HttpMessageContentConverterTests { private static final ResolvableType listOfIntegers = ResolvableType.forClassWithGenerics(List.class, Integer.class); - private static final MappingJackson2HttpMessageConverter jacksonMessageConverter = - new MappingJackson2HttpMessageConverter(new ObjectMapper()); + private static final JacksonJsonHttpMessageConverter jacksonMessageConverter = new JacksonJsonHttpMessageConverter(); @Test void createInstanceWithEmptyIterable() { diff --git a/spring-test/src/test/java/org/springframework/test/json/AbstractJsonContentAssertTests.java b/spring-test/src/test/java/org/springframework/test/json/AbstractJsonContentAssertTests.java index 307ab69fd2..87f050c85e 100644 --- a/spring-test/src/test/java/org/springframework/test/json/AbstractJsonContentAssertTests.java +++ b/spring-test/src/test/java/org/springframework/test/json/AbstractJsonContentAssertTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2024 the original author or authors. + * Copyright 2002-2025 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,7 +27,6 @@ import java.util.function.Consumer; import java.util.stream.Stream; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.databind.ObjectMapper; import org.assertj.core.api.AbstractObjectAssert; import org.assertj.core.api.AssertProvider; import org.assertj.core.api.InstanceOfAssertFactories; @@ -46,13 +45,14 @@ import org.junit.jupiter.params.provider.ValueSource; import org.skyscreamer.jsonassert.JSONCompareMode; import org.skyscreamer.jsonassert.JSONCompareResult; import org.skyscreamer.jsonassert.comparator.JSONComparator; +import tools.jackson.databind.ObjectMapper; import org.springframework.core.io.ByteArrayResource; import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.FileSystemResource; import org.springframework.core.io.InputStreamResource; import org.springframework.core.io.Resource; -import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; +import org.springframework.http.converter.json.JacksonJsonHttpMessageConverter; import org.springframework.test.http.HttpMessageContentConverter; import org.springframework.util.FileCopyUtils; @@ -86,7 +86,7 @@ class AbstractJsonContentAssertTests { private static final String DIFFERENT = loadJson("different.json"); private static final HttpMessageContentConverter jsonContentConverter = HttpMessageContentConverter.of( - new MappingJackson2HttpMessageConverter(new ObjectMapper())); + new JacksonJsonHttpMessageConverter(new ObjectMapper())); private static final JsonComparator comparator = JsonAssert.comparator(JsonCompareMode.LENIENT); @@ -113,15 +113,6 @@ class AbstractJsonContentAssertTests { .satisfies(family -> assertThat(family.familyMembers()).hasSize(5)); } - @Test - void convertToIncompatibleTargetTypeShouldFail() { - AbstractJsonContentAssert jsonAssert = assertThat(forJson(SIMPSONS, jsonContentConverter)); - assertThatExceptionOfType(AssertionError.class) - .isThrownBy(() -> jsonAssert.convertTo(Member.class)) - .withMessageContainingAll("To convert successfully to:", - Member.class.getName(), "But it failed:"); - } - @Test void convertUsingAssertFactory() { assertThat(forJson(SIMPSONS, jsonContentConverter)) diff --git a/spring-test/src/test/java/org/springframework/test/json/JsonPathValueAssertTests.java b/spring-test/src/test/java/org/springframework/test/json/JsonPathValueAssertTests.java index 12a41c164f..e79da94715 100644 --- a/spring-test/src/test/java/org/springframework/test/json/JsonPathValueAssertTests.java +++ b/spring-test/src/test/java/org/springframework/test/json/JsonPathValueAssertTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2024 the original author or authors. + * Copyright 2002-2025 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,15 +21,15 @@ import java.util.List; import java.util.Map; import java.util.function.Consumer; -import com.fasterxml.jackson.databind.ObjectMapper; import org.assertj.core.api.AssertProvider; import org.assertj.core.api.InstanceOfAssertFactories; import org.assertj.core.data.Offset; import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; +import tools.jackson.databind.ObjectMapper; -import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; +import org.springframework.http.converter.json.JacksonJsonHttpMessageConverter; import org.springframework.test.http.HttpMessageContentConverter; import org.springframework.util.StringUtils; @@ -206,7 +206,7 @@ class JsonPathValueAssertTests { class ConvertToTests { private static final HttpMessageContentConverter jsonContentConverter = HttpMessageContentConverter.of( - new MappingJackson2HttpMessageConverter(new ObjectMapper())); + new JacksonJsonHttpMessageConverter(new ObjectMapper())); @Test void convertToWithoutHttpMessageConverter() { diff --git a/spring-test/src/test/java/org/springframework/test/util/JsonPathExpectationsHelperTests.java b/spring-test/src/test/java/org/springframework/test/util/JsonPathExpectationsHelperTests.java index c61424039b..ef2a36f4b5 100644 --- a/spring-test/src/test/java/org/springframework/test/util/JsonPathExpectationsHelperTests.java +++ b/spring-test/src/test/java/org/springframework/test/util/JsonPathExpectationsHelperTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2024 the original author or authors. + * Copyright 2002-2025 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,13 +18,16 @@ package org.springframework.test.util; import java.util.List; -import com.fasterxml.jackson.databind.ObjectMapper; import com.jayway.jsonpath.Configuration; -import com.jayway.jsonpath.spi.mapper.JacksonMappingProvider; +import com.jayway.jsonpath.TypeRef; +import com.jayway.jsonpath.spi.mapper.MappingException; +import com.jayway.jsonpath.spi.mapper.MappingProvider; import org.hamcrest.CoreMatchers; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; +import tools.jackson.databind.JavaType; +import tools.jackson.databind.ObjectMapper; import org.springframework.core.ParameterizedTypeReference; @@ -45,7 +48,7 @@ import static org.hamcrest.core.Is.is; class JsonPathExpectationsHelperTests { private static final Configuration JACKSON_MAPPING_CONFIGURATION = Configuration.defaultConfiguration() - .mappingProvider(new JacksonMappingProvider(new ObjectMapper())); + .mappingProvider(new JacksonMappingProvider()); private static final String CONTENT = """ { @@ -376,4 +379,53 @@ class JsonPathExpectationsHelperTests { public record Member(String name) {} + + /** + * Jackson 3.x variant of {@link com.jayway.jsonpath.spi.mapper.JacksonMappingProvider}. + */ + private static class JacksonMappingProvider implements MappingProvider { + + private final ObjectMapper objectMapper; + + public JacksonMappingProvider() { + this(new ObjectMapper()); + } + + public JacksonMappingProvider(ObjectMapper objectMapper) { + this.objectMapper = objectMapper; + } + + + @Override + public T map(Object source, Class targetType, Configuration configuration) { + if (source == null){ + return null; + } + try { + return objectMapper.convertValue(source, targetType); + } + catch (Exception ex) { + throw new MappingException(ex); + } + + } + + @Override + @SuppressWarnings("unchecked") + public T map(Object source, final TypeRef targetType, Configuration configuration) { + if (source == null){ + return null; + } + JavaType type = objectMapper.getTypeFactory().constructType(targetType.getType()); + + try { + return (T) objectMapper.convertValue(source, type); + } + catch (Exception ex) { + throw new MappingException(ex); + } + + } + } + } diff --git a/spring-test/src/test/java/org/springframework/test/web/client/samples/matchers/ContentRequestMatchersIntegrationTests.java b/spring-test/src/test/java/org/springframework/test/web/client/samples/matchers/ContentRequestMatchersIntegrationTests.java index 98ddc7110a..fa6ee28321 100644 --- a/spring-test/src/test/java/org/springframework/test/web/client/samples/matchers/ContentRequestMatchersIntegrationTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/client/samples/matchers/ContentRequestMatchersIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2025 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,7 +23,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.http.converter.StringHttpMessageConverter; -import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; +import org.springframework.http.converter.json.JacksonJsonHttpMessageConverter; import org.springframework.test.web.Person; import org.springframework.test.web.client.MockRestServiceServer; import org.springframework.web.client.RestTemplate; @@ -52,7 +52,7 @@ class ContentRequestMatchersIntegrationTests { @BeforeEach void setup() { this.restTemplate.setMessageConverters( - List.of(new StringHttpMessageConverter(), new MappingJackson2HttpMessageConverter())); + List.of(new StringHttpMessageConverter(), new JacksonJsonHttpMessageConverter())); } diff --git a/spring-test/src/test/java/org/springframework/test/web/client/samples/matchers/HeaderRequestMatchersIntegrationTests.java b/spring-test/src/test/java/org/springframework/test/web/client/samples/matchers/HeaderRequestMatchersIntegrationTests.java index 1ea1fe609f..c4c93f6446 100644 --- a/spring-test/src/test/java/org/springframework/test/web/client/samples/matchers/HeaderRequestMatchersIntegrationTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/client/samples/matchers/HeaderRequestMatchersIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2025 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,7 +24,7 @@ import org.junit.jupiter.api.Test; import org.springframework.http.MediaType; import org.springframework.http.converter.StringHttpMessageConverter; -import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; +import org.springframework.http.converter.json.JacksonJsonHttpMessageConverter; import org.springframework.test.web.Person; import org.springframework.test.web.client.MockRestServiceServer; import org.springframework.web.client.RestTemplate; @@ -51,7 +51,7 @@ class HeaderRequestMatchersIntegrationTests { @BeforeEach void setup() { this.restTemplate.setMessageConverters( - List.of(new StringHttpMessageConverter(), new MappingJackson2HttpMessageConverter())); + List.of(new StringHttpMessageConverter(), new JacksonJsonHttpMessageConverter())); } diff --git a/spring-test/src/test/java/org/springframework/test/web/client/samples/matchers/JsonPathRequestMatchersIntegrationTests.java b/spring-test/src/test/java/org/springframework/test/web/client/samples/matchers/JsonPathRequestMatchersIntegrationTests.java index 85b857f2bb..fb9f2acd22 100644 --- a/spring-test/src/test/java/org/springframework/test/web/client/samples/matchers/JsonPathRequestMatchersIntegrationTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/client/samples/matchers/JsonPathRequestMatchersIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2025 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,7 +22,7 @@ import java.util.Collections; import org.junit.jupiter.api.Test; -import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; +import org.springframework.http.converter.json.JacksonJsonHttpMessageConverter; import org.springframework.test.web.Person; import org.springframework.test.web.client.MockRestServiceServer; import org.springframework.util.LinkedMultiValueMap; @@ -65,7 +65,7 @@ class JsonPathRequestMatchersIntegrationTests { private final RestTemplate restTemplate = - new RestTemplate(Collections.singletonList(new MappingJackson2HttpMessageConverter())); + new RestTemplate(Collections.singletonList(new JacksonJsonHttpMessageConverter())); private final MockRestServiceServer mockServer = MockRestServiceServer.createServer(this.restTemplate); diff --git a/spring-test/src/test/java/org/springframework/test/web/reactive/server/EncoderDecoderMappingProviderTests.java b/spring-test/src/test/java/org/springframework/test/web/reactive/server/EncoderDecoderMappingProviderTests.java index e2c9d27a37..e9a580e37f 100644 --- a/spring-test/src/test/java/org/springframework/test/web/reactive/server/EncoderDecoderMappingProviderTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/reactive/server/EncoderDecoderMappingProviderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2024 the original author or authors. + * Copyright 2002-2025 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,13 +19,13 @@ package org.springframework.test.web.reactive.server; import java.util.List; import java.util.Map; -import com.fasterxml.jackson.databind.ObjectMapper; import com.jayway.jsonpath.Configuration; import com.jayway.jsonpath.TypeRef; import org.junit.jupiter.api.Test; +import tools.jackson.databind.ObjectMapper; -import org.springframework.http.codec.json.Jackson2JsonDecoder; -import org.springframework.http.codec.json.Jackson2JsonEncoder; +import org.springframework.http.codec.json.JacksonJsonDecoder; +import org.springframework.http.codec.json.JacksonJsonEncoder; import static org.assertj.core.api.Assertions.assertThat; @@ -39,7 +39,7 @@ class EncoderDecoderMappingProviderTests { private static final ObjectMapper objectMapper = new ObjectMapper(); private final EncoderDecoderMappingProvider mappingProvider = new EncoderDecoderMappingProvider( - new Jackson2JsonEncoder(objectMapper), new Jackson2JsonDecoder(objectMapper)); + new JacksonJsonEncoder(objectMapper), new JacksonJsonDecoder(objectMapper)); @Test diff --git a/spring-test/src/test/java/org/springframework/test/web/reactive/server/JsonEncoderDecoderTests.java b/spring-test/src/test/java/org/springframework/test/web/reactive/server/JsonEncoderDecoderTests.java index 6655b071f7..e8c4c8f10b 100644 --- a/spring-test/src/test/java/org/springframework/test/web/reactive/server/JsonEncoderDecoderTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/reactive/server/JsonEncoderDecoderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2024 the original author or authors. + * Copyright 2002-2025 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,8 +18,8 @@ package org.springframework.test.web.reactive.server; import java.util.List; -import com.fasterxml.jackson.databind.ObjectMapper; import org.junit.jupiter.api.Test; +import tools.jackson.databind.ObjectMapper; import org.springframework.http.codec.DecoderHttpMessageReader; import org.springframework.http.codec.EncoderHttpMessageWriter; @@ -27,8 +27,8 @@ import org.springframework.http.codec.HttpMessageReader; import org.springframework.http.codec.HttpMessageWriter; import org.springframework.http.codec.ResourceHttpMessageReader; import org.springframework.http.codec.ResourceHttpMessageWriter; -import org.springframework.http.codec.json.Jackson2JsonDecoder; -import org.springframework.http.codec.json.Jackson2JsonEncoder; +import org.springframework.http.codec.json.JacksonJsonDecoder; +import org.springframework.http.codec.json.JacksonJsonEncoder; import static org.assertj.core.api.Assertions.assertThat; @@ -42,10 +42,10 @@ class JsonEncoderDecoderTests { private static final ObjectMapper objectMapper = new ObjectMapper(); private static final HttpMessageWriter jacksonMessageWriter = new EncoderHttpMessageWriter<>( - new Jackson2JsonEncoder(objectMapper)); + new JacksonJsonEncoder(objectMapper)); private static final HttpMessageReader jacksonMessageReader = new DecoderHttpMessageReader<>( - new Jackson2JsonDecoder(objectMapper)); + new JacksonJsonDecoder(objectMapper)); @Test void fromWithEmptyWriters() { @@ -73,8 +73,8 @@ class JsonEncoderDecoderTests { List.of(new ResourceHttpMessageWriter(), jacksonMessageWriter), List.of(new ResourceHttpMessageReader(), jacksonMessageReader)); assertThat(jsonEncoderDecoder).isNotNull(); - assertThat(jsonEncoderDecoder.encoder()).isInstanceOf(Jackson2JsonEncoder.class); - assertThat(jsonEncoderDecoder.decoder()).isInstanceOf(Jackson2JsonDecoder.class); + assertThat(jsonEncoderDecoder.encoder()).isInstanceOf(JacksonJsonEncoder.class); + assertThat(jsonEncoderDecoder.decoder()).isInstanceOf(JacksonJsonDecoder.class); } } diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/assertj/MockMvcTesterTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/assertj/MockMvcTesterTests.java index ec3625f08e..72c93e94d8 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/assertj/MockMvcTesterTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/assertj/MockMvcTesterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2024 the original author or authors. + * Copyright 2002-2025 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,7 +22,6 @@ import java.util.List; import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Consumer; -import com.fasterxml.jackson.databind.ObjectMapper; import jakarta.servlet.ServletContext; import jakarta.servlet.ServletException; import org.jspecify.annotations.Nullable; @@ -32,10 +31,11 @@ import org.springframework.cglib.core.internal.Function; import org.springframework.context.annotation.AnnotationConfigUtils; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.core.ResolvableType; import org.springframework.http.HttpMethod; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; -import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; +import org.springframework.http.converter.json.JacksonJsonHttpMessageConverter; import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.mock.web.MockServletContext; import org.springframework.test.json.AbstractJsonContentAssert; @@ -62,8 +62,8 @@ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilder */ class MockMvcTesterTests { - private static final MappingJackson2HttpMessageConverter jsonHttpMessageConverter = - new MappingJackson2HttpMessageConverter(new ObjectMapper()); + private static final JacksonJsonHttpMessageConverter jsonHttpMessageConverter = + new JacksonJsonHttpMessageConverter(); private final ServletContext servletContext = new MockServletContext(); @@ -128,7 +128,7 @@ class MockMvcTesterTests { @Test void withHttpMessageConverterUsesConverter() { - MappingJackson2HttpMessageConverter converter = spy(jsonHttpMessageConverter); + JacksonJsonHttpMessageConverter converter = spy(jsonHttpMessageConverter); MockMvcTester mockMvc = MockMvcTester.of(HelloController.class) .withHttpMessageConverters(List.of(mock(), mock(), converter)); assertThat(mockMvc.perform(get("/json"))).hasStatusOk().bodyJson() @@ -136,7 +136,7 @@ class MockMvcTesterTests { assertThat(message.message()).isEqualTo("Hello World"); assertThat(message.counter()).isEqualTo(42); }); - verify(converter).canWrite(LinkedHashMap.class, LinkedHashMap.class, MediaType.APPLICATION_JSON); + verify(converter).canWrite(ResolvableType.forClass(LinkedHashMap.class), LinkedHashMap.class, MediaType.APPLICATION_JSON); } @Test diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/client/standalone/FilterTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/client/standalone/FilterTests.java index c555cfb364..0ec113ab1a 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/client/standalone/FilterTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/client/standalone/FilterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2024 the original author or authors. + * Copyright 2002-2025 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -162,7 +162,7 @@ public class FilterTests { .exchange() .expectStatus().isOk() .expectHeader().contentLength(53) - .expectHeader().valueEquals("ETag", "\"0e37becb4f0c90709cb2e1efcc61eaa00\"") + .expectHeader().valueEquals("ETag", "\"08ff7f2f1f370ada7db137770dada33a0\"") .expectBody().json("{\"name\":\"Lukas\",\"someDouble\":0.0,\"someBoolean\":false}"); } diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/context/JavaConfigTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/context/JavaConfigTests.java index 06e7869c02..700b6561a6 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/context/JavaConfigTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/context/JavaConfigTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2024 the original author or authors. + * Copyright 2002-2025 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -97,7 +97,7 @@ public class JavaConfigTests { .andExpectAll( status().isOk(), request().asyncNotStarted(), - content().string("{\"name\":\"Joe\",\"someDouble\":0.0,\"someBoolean\":false}"), + content().string("{\"name\":\"Joe\",\"someBoolean\":false,\"someDouble\":0.0}"), jsonPath("$.name").value("Joe") ); } diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/AsyncTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/AsyncTests.java index ee2841538c..2e0524eef4 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/AsyncTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/AsyncTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2024 the original author or authors. + * Copyright 2002-2025 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -77,7 +77,7 @@ class AsyncTests { this.mockMvc.perform(asyncDispatch(mvcResult)) .andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(content().string("{\"name\":\"Joe\",\"someDouble\":0.0,\"someBoolean\":false}")); + .andExpect(content().string("{\"name\":\"Joe\",\"someBoolean\":false,\"someDouble\":0.0}")); } @Test @@ -117,7 +117,7 @@ class AsyncTests { this.mockMvc.perform(asyncDispatch(mvcResult)) .andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(content().string("{\"name\":\"Joe\",\"someDouble\":0.0,\"someBoolean\":false}")); + .andExpect(content().string("{\"name\":\"Joe\",\"someBoolean\":false,\"someDouble\":0.0}")); } @Test @@ -130,7 +130,7 @@ class AsyncTests { this.mockMvc.perform(asyncDispatch(mvcResult)) .andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(content().string("{\"name\":\"Joe\",\"someDouble\":0.0,\"someBoolean\":false}")); + .andExpect(content().string("{\"name\":\"Joe\",\"someBoolean\":false,\"someDouble\":0.0}")); } @Test // SPR-13079 @@ -153,7 +153,7 @@ class AsyncTests { this.mockMvc.perform(asyncDispatch(mvcResult)) .andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(content().string("{\"name\":\"Joe\",\"someDouble\":0.0,\"someBoolean\":false}")); + .andExpect(content().string("{\"name\":\"Joe\",\"someBoolean\":false,\"someDouble\":0.0}")); } @Test // SPR-12735 @@ -172,7 +172,7 @@ class AsyncTests { .andDo(print(writer)) .andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(content().string("{\"name\":\"Joe\",\"someDouble\":0.0,\"someBoolean\":false}")); + .andExpect(content().string("{\"name\":\"Joe\",\"someBoolean\":false,\"someDouble\":0.0}")); assertThat(writer.toString()).contains("Async started = false"); } @@ -188,7 +188,7 @@ class AsyncTests { assertThat(mockMvc.get().uri("/1").param("callable", "true")) .hasStatusOk() .hasContentTypeCompatibleWith(MediaType.APPLICATION_JSON) - .hasBodyTextEqualTo("{\"name\":\"Joe\",\"someDouble\":0.0,\"someBoolean\":false}"); + .hasBodyTextEqualTo("{\"name\":\"Joe\",\"someBoolean\":false,\"someDouble\":0.0}"); } @Test @@ -216,7 +216,7 @@ class AsyncTests { assertThat(this.mockMvc.get().uri("/1").param("deferredResult", "true")) .hasStatusOk() .hasContentTypeCompatibleWith(MediaType.APPLICATION_JSON) - .hasBodyTextEqualTo("{\"name\":\"Joe\",\"someDouble\":0.0,\"someBoolean\":false}"); + .hasBodyTextEqualTo("{\"name\":\"Joe\",\"someBoolean\":false,\"someDouble\":0.0}"); } @Test @@ -224,7 +224,7 @@ class AsyncTests { assertThat(this.mockMvc.get().uri("/1").param("deferredResultWithImmediateValue", "true")) .hasStatusOk() .hasContentTypeCompatibleWith(MediaType.APPLICATION_JSON) - .hasBodyTextEqualTo("{\"name\":\"Joe\",\"someDouble\":0.0,\"someBoolean\":false}"); + .hasBodyTextEqualTo("{\"name\":\"Joe\",\"someBoolean\":false,\"someDouble\":0.0}"); } @Test // SPR-13079 @@ -238,7 +238,7 @@ class AsyncTests { assertThat(this.mockMvc.get().uri("/1").param("completableFutureWithImmediateValue", "true")) .hasStatusOk() .hasContentTypeCompatibleWith(MediaType.APPLICATION_JSON) - .hasBodyTextEqualTo("{\"name\":\"Joe\",\"someDouble\":0.0,\"someBoolean\":false}"); + .hasBodyTextEqualTo("{\"name\":\"Joe\",\"someBoolean\":false,\"someDouble\":0.0}"); } @Test // SPR-12735 @@ -253,7 +253,7 @@ class AsyncTests { .debug(asyncWriter) .hasStatusOk() .hasContentTypeCompatibleWith(MediaType.APPLICATION_JSON) - .hasBodyTextEqualTo("{\"name\":\"Joe\",\"someDouble\":0.0,\"someBoolean\":false}"); + .hasBodyTextEqualTo("{\"name\":\"Joe\",\"someBoolean\":false,\"someDouble\":0.0}"); assertThat(asyncWriter.toString()).contains("Async started = false"); } } diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/FilterTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/FilterTests.java index 683870f677..a22a395900 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/FilterTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/FilterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2024 the original author or authors. + * Copyright 2002-2025 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -139,8 +139,8 @@ public class FilterTests { mockMvc.perform(asyncDispatch(mvcResult)) .andExpect(status().isOk()) .andExpect(header().longValue("Content-Length", 53)) - .andExpect(header().string("ETag", "\"0e37becb4f0c90709cb2e1efcc61eaa00\"")) - .andExpect(content().string("{\"name\":\"Lukas\",\"someDouble\":0.0,\"someBoolean\":false}")); + .andExpect(header().string("ETag", "\"08ff7f2f1f370ada7db137770dada33a0\"")) + .andExpect(content().string("{\"name\":\"Lukas\",\"someBoolean\":false,\"someDouble\":0.0}")); } diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/ViewResolutionTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/ViewResolutionTests.java index 1925ae9ffb..7f9ee15e14 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/ViewResolutionTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/ViewResolutionTests.java @@ -36,7 +36,6 @@ import org.springframework.web.servlet.View; import org.springframework.web.servlet.view.ContentNegotiatingViewResolver; import org.springframework.web.servlet.view.InternalResourceViewResolver; import org.springframework.web.servlet.view.json.JacksonJsonView; -import org.springframework.web.servlet.view.json.MappingJackson2JsonView; import org.springframework.web.servlet.view.xml.MarshallingView; import static org.hamcrest.Matchers.equalTo; @@ -96,7 +95,7 @@ class ViewResolutionTests { marshaller.setClassesToBeBound(Person.class); List viewList = new ArrayList<>(); - viewList.add(new MappingJackson2JsonView()); + viewList.add(new JacksonJsonView()); viewList.add(new MarshallingView(marshaller)); ContentNegotiationManager manager = new ContentNegotiationManager( diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/setup/StandaloneMockMvcBuilderTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/setup/StandaloneMockMvcBuilderTests.java index b352e88591..0d120a5832 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/setup/StandaloneMockMvcBuilderTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/setup/StandaloneMockMvcBuilderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2024 the original author or authors. + * Copyright 2002-2025 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,8 +20,6 @@ import java.io.IOException; import java.util.EnumSet; import java.util.Map; -import com.fasterxml.jackson.databind.JsonSerializer; -import com.fasterxml.jackson.databind.ser.impl.UnknownSerializer; import jakarta.servlet.DispatcherType; import jakarta.servlet.Filter; import jakarta.servlet.FilterChain; @@ -31,8 +29,10 @@ import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; +import tools.jackson.databind.ValueSerializer; +import tools.jackson.databind.ser.impl.UnknownSerializer; -import org.springframework.http.converter.json.SpringHandlerInstantiator; +import org.springframework.http.support.JacksonHandlerInstantiator; import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.stereotype.Controller; import org.springframework.test.web.servlet.MockMvc; @@ -133,8 +133,8 @@ class StandaloneMockMvcBuilderTests { void springHandlerInstantiator() { TestStandaloneMockMvcBuilder builder = new TestStandaloneMockMvcBuilder(new PersonController()); builder.build(); - SpringHandlerInstantiator instantiator = new SpringHandlerInstantiator(builder.wac.getAutowireCapableBeanFactory()); - JsonSerializer serializer = instantiator.serializerInstance(null, null, UnknownSerializer.class); + JacksonHandlerInstantiator instantiator = new JacksonHandlerInstantiator(builder.wac.getAutowireCapableBeanFactory()); + ValueSerializer serializer = instantiator.serializerInstance(null, null, UnknownSerializer.class); assertThat(serializer).isNotNull(); }