Upgrade to Spring Framework 7.0.0-M5

This commit also adapts to the new Jackson 3.0 baseline.

Closes gh-1202
This commit is contained in:
Brian Clozel
2025-05-20 18:59:04 +02:00
parent ce90154953
commit 7d7749a2b2
39 changed files with 462 additions and 161 deletions

View File

@@ -14,6 +14,7 @@ dependencies {
compileOnly 'org.springframework:spring-websocket'
compileOnly 'org.springframework:spring-messaging'
compileOnly 'jakarta.servlet:jakarta.servlet-api'
compileOnly 'tools.jackson.core:jackson-databind'
compileOnly 'io.rsocket:rsocket-core'
compileOnly 'io.rsocket:rsocket-transport-netty'
compileOnly 'org.skyscreamer:jsonassert'
@@ -32,7 +33,7 @@ dependencies {
testImplementation 'io.projectreactor.netty:reactor-netty'
testImplementation 'io.rsocket:rsocket-transport-local'
testImplementation 'io.micrometer:context-propagation'
testImplementation 'com.fasterxml.jackson.core:jackson-databind'
testImplementation 'tools.jackson.core:jackson-databind'
testRuntimeOnly 'org.apache.logging.log4j:log4j-core'
testRuntimeOnly 'org.apache.logging.log4j:log4j-slf4j-impl'

View File

@@ -24,8 +24,6 @@ import java.util.function.Function;
import java.util.function.Predicate;
import com.jayway.jsonpath.Configuration;
import com.jayway.jsonpath.spi.json.JacksonJsonProvider;
import com.jayway.jsonpath.spi.mapper.JacksonMappingProvider;
import com.jayway.jsonpath.spi.mapper.MappingProvider;
import org.jspecify.annotations.Nullable;
import reactor.core.publisher.Flux;
@@ -60,8 +58,8 @@ import org.springframework.util.ClassUtils;
*/
public abstract class AbstractGraphQlTesterBuilder<B extends AbstractGraphQlTesterBuilder<B>> implements GraphQlTester.Builder<B> {
private static final boolean jackson2Present = ClassUtils.isPresent(
"com.fasterxml.jackson.databind.ObjectMapper", AbstractGraphQlClientBuilder.class.getClassLoader());
private static final boolean jacksonPresent = ClassUtils.isPresent(
"tools.jackson.databind.ObjectMapper", AbstractGraphQlClientBuilder.class.getClassLoader());
private static final Duration DEFAULT_RESPONSE_DURATION = Duration.ofSeconds(5);
@@ -130,8 +128,8 @@ public abstract class AbstractGraphQlTesterBuilder<B extends AbstractGraphQlTest
*/
protected GraphQlTester buildGraphQlTester(GraphQlTransport transport) {
if (jackson2Present) {
configureJsonPathConfig(Jackson2Configurer::configure);
if (jacksonPresent) {
configureJsonPathConfig(JacksonConfigurer::configure);
}
return new DefaultGraphQlTester(transport, this.errorFilter,
@@ -195,7 +193,7 @@ public abstract class AbstractGraphQlTesterBuilder<B extends AbstractGraphQlTest
}
private static final class Jackson2Configurer {
private static final class JacksonConfigurer {
private static final Class<?> defaultJsonProviderType;

View File

@@ -0,0 +1,88 @@
/*
* Copyright 2020-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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.graphql.test.tester;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.StringWriter;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import com.jayway.jsonpath.InvalidJsonException;
import com.jayway.jsonpath.spi.json.AbstractJsonProvider;
import tools.jackson.core.JacksonException;
import tools.jackson.core.JsonGenerator;
import tools.jackson.databind.ObjectMapper;
import tools.jackson.databind.ObjectReader;
/**
* {@link com.jayway.jsonpath.spi.json.JsonProvider} for Jackson 3.x.
* @author Brian Clozel
*/
class JacksonJsonProvider extends AbstractJsonProvider {
private final ObjectMapper objectMapper = new ObjectMapper();
private final ObjectReader objectReader = this.objectMapper.reader();
@Override
public Object parse(String json) throws InvalidJsonException {
try {
return this.objectReader.readValue(json);
}
catch (JacksonException exc) {
throw new InvalidJsonException(exc, json);
}
}
@Override
public Object parse(InputStream jsonStream, String charset) throws InvalidJsonException {
try {
return this.objectReader.readValue(new InputStreamReader(jsonStream, charset));
}
catch (IOException exc) {
throw new InvalidJsonException(exc);
}
}
@Override
public String toJson(Object obj) {
StringWriter writer = new StringWriter();
try {
JsonGenerator generator = this.objectMapper.createGenerator(writer);
this.objectMapper.writeValue(generator, obj);
writer.flush();
writer.close();
generator.close();
return writer.getBuffer().toString();
}
catch (IOException exc) {
throw new InvalidJsonException(exc);
}
}
@Override
public Object createArray() {
return new LinkedList<Object>();
}
@Override
public Object createMap() {
return new LinkedHashMap<String, Object>();
}
}

View File

@@ -0,0 +1,65 @@
/*
* Copyright 2020-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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.graphql.test.tester;
import com.jayway.jsonpath.Configuration;
import com.jayway.jsonpath.TypeRef;
import com.jayway.jsonpath.spi.mapper.MappingException;
import com.jayway.jsonpath.spi.mapper.MappingProvider;
import org.jspecify.annotations.Nullable;
import tools.jackson.databind.JavaType;
import tools.jackson.databind.ObjectMapper;
/**
* {@link MappingProvider} for Jackson 3.x.
* @author Brian Clozel
*/
class JacksonMappingProvider implements MappingProvider {
private final ObjectMapper objectMapper = new ObjectMapper();
@Override
public <T> @Nullable T map(@Nullable Object source, Class<T> targetType, Configuration configuration) {
if (source == null) {
return null;
}
try {
return this.objectMapper.convertValue(source, targetType);
}
catch (Exception exc) {
throw new MappingException(exc);
}
}
@Override
@SuppressWarnings("unchecked")
public <T> @Nullable T map(@Nullable Object source, final TypeRef<T> targetType, Configuration configuration) {
if (source == null) {
return null;
}
JavaType type = this.objectMapper.getTypeFactory().constructType(targetType.getType());
try {
return (T) this.objectMapper.convertValue(source, type);
}
catch (Exception exc) {
throw new MappingException(exc);
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 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.
@@ -31,8 +31,8 @@ import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.graphql.ExecutionGraphQlRequest;
import org.springframework.graphql.ExecutionGraphQlService;
import org.springframework.graphql.support.DocumentSource;
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 org.springframework.lang.Nullable;
import org.springframework.util.MimeType;
@@ -91,10 +91,10 @@ class GraphQlTesterBuilderTests extends GraphQlTesterTestSupport {
@Test
void codecConfigurerRegistersJsonPathMappingProvider() {
TestJackson2JsonDecoder testDecoder = new TestJackson2JsonDecoder();
TestJacksonJsonDecoder testDecoder = new TestJacksonJsonDecoder();
ExecutionGraphQlServiceTester.Builder<?> builder = graphQlTesterBuilder()
.encoder(new Jackson2JsonEncoder())
.encoder(new JacksonJsonEncoder())
.decoder(testDecoder);
String document = "{me {name}}";
@@ -138,7 +138,7 @@ class GraphQlTesterBuilderTests extends GraphQlTesterTestSupport {
}
private static class TestJackson2JsonDecoder extends Jackson2JsonDecoder {
private static class TestJacksonJsonDecoder extends JacksonJsonDecoder {
@Nullable
private Object lastValue;

View File

@@ -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.
@@ -36,8 +36,8 @@ import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.graphql.GraphQlRequest;
import org.springframework.graphql.execution.MockExecutionGraphQlService;
import org.springframework.graphql.server.GraphQlRSocketHandler;
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 org.springframework.lang.Nullable;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.rsocket.RSocketStrategies;
@@ -87,12 +87,12 @@ class RSocketGraphQlTesterBuilderTests {
@Test
void rsocketStrategiesRegistersJsonPathMappingProvider() {
TestJackson2JsonDecoder testDecoder = new TestJackson2JsonDecoder();
TestJacksonJsonDecoder testDecoder = new TestJacksonJsonDecoder();
RSocketGraphQlTester.Builder<?> builder = this.builderSetup.initBuilder()
.rsocketRequester(requesterBuilder -> {
RSocketStrategies strategies = RSocketStrategies.builder()
.encoder(new Jackson2JsonEncoder())
.encoder(new JacksonJsonEncoder())
.decoder(testDecoder)
.build();
requesterBuilder.rsocketStrategies(strategies);
@@ -132,7 +132,7 @@ class RSocketGraphQlTesterBuilderTests {
public RSocketGraphQlTester.Builder<?> initBuilder() {
GraphQlRSocketController controller = new GraphQlRSocketController(
new GraphQlRSocketHandler(this.graphQlService, Collections.emptyList(), new Jackson2JsonEncoder()));
new GraphQlRSocketHandler(this.graphQlService, Collections.emptyList(), new JacksonJsonEncoder()));
this.server = RSocketServer.create()
.acceptor(createSocketAcceptor(controller))
@@ -146,8 +146,8 @@ class RSocketGraphQlTesterBuilderTests {
private SocketAcceptor createSocketAcceptor(GraphQlRSocketController controller) {
RSocketStrategies.Builder builder = RSocketStrategies.builder();
builder.encoder(new Jackson2JsonEncoder());
builder.decoder(new Jackson2JsonDecoder());
builder.encoder(new JacksonJsonEncoder());
builder.decoder(new JacksonJsonDecoder());
RSocketMessageHandler handler = new RSocketMessageHandler();
handler.setHandlers(Collections.singletonList(controller));
@@ -195,7 +195,7 @@ class RSocketGraphQlTesterBuilderTests {
}
private static class TestJackson2JsonDecoder extends Jackson2JsonDecoder {
private static class TestJacksonJsonDecoder extends JacksonJsonDecoder {
@Nullable
private Object lastValue;

View File

@@ -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.
@@ -42,7 +42,7 @@ import org.springframework.graphql.server.webflux.GraphQlHttpHandler;
import org.springframework.graphql.server.webflux.GraphQlWebSocketHandler;
import org.springframework.graphql.support.DocumentSource;
import org.springframework.http.codec.ClientCodecConfigurer;
import org.springframework.http.codec.json.Jackson2JsonDecoder;
import org.springframework.http.codec.json.JacksonJsonDecoder;
import org.springframework.lang.Nullable;
import org.springframework.test.web.reactive.server.WebTestClient;
import org.springframework.util.Assert;
@@ -168,7 +168,7 @@ class WebGraphQlTesterBuilderTests {
@MethodSource("argumentSource")
void codecConfigurerRegistersJsonPathMappingProvider(TesterBuilderSetup builderSetup) {
TestJackson2JsonDecoder testDecoder = new TestJackson2JsonDecoder();
TestJacksonJsonDecoder testDecoder = new TestJacksonJsonDecoder();
WebGraphQlTester.Builder<?> builder = builderSetup.initBuilder()
.codecConfigurer(codecConfigurer -> codecConfigurer.customCodecs().register(testDecoder));
@@ -267,7 +267,7 @@ class WebGraphQlTesterBuilderTests {
}
private static class TestJackson2JsonDecoder extends Jackson2JsonDecoder {
private static class TestJacksonJsonDecoder extends JacksonJsonDecoder {
@Nullable
private Object lastValue;