Update spring-test tests to use Jackson 3
See gh-33798
This commit is contained in:
@@ -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")
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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> T map(Object source, Class<T> 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> T map(Object source, final TypeRef<T> 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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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()));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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()));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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}");
|
||||
}
|
||||
|
||||
|
||||
@@ -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")
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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}"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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<View> viewList = new ArrayList<>();
|
||||
viewList.add(new MappingJackson2JsonView());
|
||||
viewList.add(new JacksonJsonView());
|
||||
viewList.add(new MarshallingView(marshaller));
|
||||
|
||||
ContentNegotiationManager manager = new ContentNegotiationManager(
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user