Polish Jackson 3 support

- Improve Javadoc.

- Suppress warnings for "removal".

- Update copyright headers.

- Migrate several tests from:
  - MappingJackson2MessageConverter to JacksonJsonMessageConverter
  - Jackson2JsonEncoder to JacksonJsonEncoder
  - Jackson2JsonDecoder to JacksonJsonDecoder
  - Jackson2SmileEncoder to JacksonSmileEncoder
  - Jackson2ObjectMapperBuilder to JsonMapper and XmlMapper
  - MappingJackson2JsonView to JacksonJsonView
  - MappingJackson2HttpMessageConverter to JacksonJsonHttpMessageConverter
  - MappingJackson2XmlHttpMessageConverter to JacksonXmlHttpMessageConverter
This commit is contained in:
Sam Brannen
2025-05-14 16:55:27 +02:00
parent ea340fbe69
commit 01fea5e7ed
88 changed files with 402 additions and 346 deletions

View File

@@ -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.
@@ -16,7 +16,6 @@
package org.springframework.messaging.core;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@@ -38,29 +37,20 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
*/
class DestinationResolvingMessagingTemplateTests {
private TestDestinationResolvingMessagingTemplate template;
private final TestDestinationResolvingMessagingTemplate template = new TestDestinationResolvingMessagingTemplate();
private ExecutorSubscribableChannel myChannel;
private final ExecutorSubscribableChannel myChannel = new ExecutorSubscribableChannel();
private Map<String, Object> headers;
private final Map<String, Object> headers = Map.of("key", "value");
private TestMessagePostProcessor postProcessor;
private final TestMessagePostProcessor postProcessor = new TestMessagePostProcessor();
@BeforeEach
void setup() {
TestMessageChannelDestinationResolver resolver = new TestMessageChannelDestinationResolver();
this.myChannel = new ExecutorSubscribableChannel();
resolver.registerMessageChannel("myChannel", this.myChannel);
this.template = new TestDestinationResolvingMessagingTemplate();
this.template.setDestinationResolver(resolver);
this.headers = Collections.singletonMap("key", "value");
this.postProcessor = new TestMessagePostProcessor();
}
@@ -76,8 +66,8 @@ class DestinationResolvingMessagingTemplateTests {
@Test
void sendNoDestinationResolver() {
TestDestinationResolvingMessagingTemplate template = new TestDestinationResolvingMessagingTemplate();
assertThatIllegalStateException().isThrownBy(() ->
template.send("myChannel", new GenericMessage<>("payload")));
assertThatIllegalStateException()
.isThrownBy(() -> template.send("myChannel", new GenericMessage<>("payload")));
}
@Test
@@ -240,19 +230,21 @@ class DestinationResolvingMessagingTemplateTests {
}
}
}
class TestMessageChannelDestinationResolver implements DestinationResolver<MessageChannel> {
private static class TestMessageChannelDestinationResolver implements DestinationResolver<MessageChannel> {
private final Map<String, MessageChannel> channels = new HashMap<>();
private final Map<String, MessageChannel> channels = new HashMap<>();
public void registerMessageChannel(String name, MessageChannel channel) {
this.channels.put(name, channel);
public void registerMessageChannel(String name, MessageChannel channel) {
this.channels.put(name, channel);
}
@Override
public MessageChannel resolveDestination(String name) throws DestinationResolutionException {
return this.channels.get(name);
}
}
@Override
public MessageChannel resolveDestination(String name) throws DestinationResolutionException {
return this.channels.get(name);
}
}

View File

@@ -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,13 +21,12 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHeaders;
import org.springframework.messaging.converter.CompositeMessageConverter;
import org.springframework.messaging.converter.MappingJackson2MessageConverter;
import org.springframework.messaging.converter.JacksonJsonMessageConverter;
import org.springframework.messaging.converter.MessageConversionException;
import org.springframework.messaging.converter.MessageConverter;
import org.springframework.messaging.converter.StringMessageConverter;
@@ -47,21 +46,15 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
*/
class MessageSendingTemplateTests {
private TestMessageSendingTemplate template;
private final TestMessageSendingTemplate template = new TestMessageSendingTemplate();
private TestMessagePostProcessor postProcessor;
private final TestMessagePostProcessor postProcessor = new TestMessagePostProcessor();
private Map<String, Object> headers;
private final Map<String, Object> headers = new HashMap<>() {{
put("key", "value");
}};
@BeforeEach
void setup() {
this.template = new TestMessageSendingTemplate();
this.postProcessor = new TestMessagePostProcessor();
this.headers = new HashMap<>();
this.headers.put("key", "value");
}
@Test
void send() {
Message<?> message = new GenericMessage<Object>("payload");
@@ -84,8 +77,7 @@ class MessageSendingTemplateTests {
@Test
void sendMissingDestination() {
Message<?> message = new GenericMessage<Object>("payload");
assertThatIllegalStateException().isThrownBy(() ->
this.template.send(message));
assertThatIllegalStateException().isThrownBy(() -> this.template.send(message));
}
@Test
@@ -177,14 +169,12 @@ class MessageSendingTemplateTests {
@Test
void convertAndSendNoMatchingConverter() {
MessageConverter converter = new CompositeMessageConverter(
List.of(new MappingJackson2MessageConverter()));
MessageConverter converter = new CompositeMessageConverter(List.of(new JacksonJsonMessageConverter()));
this.template.setMessageConverter(converter);
this.headers.put(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.APPLICATION_XML);
assertThatExceptionOfType(MessageConversionException.class).isThrownBy(() ->
this.template.convertAndSend("home", "payload", new MessageHeaders(this.headers)));
assertThatExceptionOfType(MessageConversionException.class)
.isThrownBy(() -> this.template.convertAndSend("home", "payload", new MessageHeaders(this.headers)));
}
@@ -202,19 +192,3 @@ class MessageSendingTemplateTests {
}
}
class TestMessagePostProcessor implements MessagePostProcessor {
private Message<?> message;
Message<?> getMessage() {
return this.message;
}
@Override
public Message<?> postProcessMessage(Message<?> message) {
this.message = message;
return message;
}
}

View File

@@ -0,0 +1,36 @@
/*
* 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.
* 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.messaging.core;
import org.springframework.messaging.Message;
public class TestMessagePostProcessor implements MessagePostProcessor {
private Message<?> message;
Message<?> getMessage() {
return this.message;
}
@Override
public Message<?> postProcessMessage(Message<?> message) {
this.message = message;
return message;
}
}

View File

@@ -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.
@@ -218,6 +218,7 @@ class MessageMethodArgumentResolverTests {
}
@Test // SPR-16486
@SuppressWarnings("removal")
public void resolveWithJacksonConverter() throws Exception {
Message<String> inMessage = MessageBuilder.withPayload("{\"foo\":\"bar\"}").build();
MethodParameter parameter = new MethodParameter(this.method, 5);