Skip to content

Commit 01fea5e

Browse files
committed
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
1 parent ea340fb commit 01fea5e

File tree

88 files changed

+402
-346
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+402
-346
lines changed

spring-jms/src/test/java/org/springframework/jms/listener/adapter/MessagingMessageListenerAdapterTests.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -70,7 +70,8 @@ class MessagingMessageListenerAdapterTests {
7070

7171
@BeforeEach
7272
void setup() {
73-
initializeFactory(factory);
73+
factory.setBeanFactory(new StaticListableBeanFactory());
74+
factory.afterPropertiesSet();
7475
}
7576

7677
@Test
@@ -405,11 +406,6 @@ protected Object extractMessage(jakarta.jms.Message message) {
405406
return adapter;
406407
}
407408

408-
private void initializeFactory(DefaultMessageHandlerMethodFactory factory) {
409-
factory.setBeanFactory(new StaticListableBeanFactory());
410-
factory.afterPropertiesSet();
411-
}
412-
413409

414410
@SuppressWarnings("unused")
415411
private static class SampleBean {

spring-jms/src/test/java/org/springframework/jms/support/converter/MappingJackson2MessageConverterTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2024 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -49,6 +49,7 @@
4949
* @author Dave Syer
5050
* @author Stephane Nicoll
5151
*/
52+
@SuppressWarnings("removal")
5253
class MappingJackson2MessageConverterTests {
5354

5455
private MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter();

spring-messaging/src/test/java/org/springframework/messaging/core/DestinationResolvingMessagingTemplateTests.java

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2024 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,7 +16,6 @@
1616

1717
package org.springframework.messaging.core;
1818

19-
import java.util.Collections;
2019
import java.util.HashMap;
2120
import java.util.Map;
2221

@@ -38,29 +37,20 @@
3837
*/
3938
class DestinationResolvingMessagingTemplateTests {
4039

41-
private TestDestinationResolvingMessagingTemplate template;
40+
private final TestDestinationResolvingMessagingTemplate template = new TestDestinationResolvingMessagingTemplate();
4241

43-
private ExecutorSubscribableChannel myChannel;
42+
private final ExecutorSubscribableChannel myChannel = new ExecutorSubscribableChannel();
4443

45-
private Map<String, Object> headers;
44+
private final Map<String, Object> headers = Map.of("key", "value");
4645

47-
private TestMessagePostProcessor postProcessor;
46+
private final TestMessagePostProcessor postProcessor = new TestMessagePostProcessor();
4847

4948

5049
@BeforeEach
5150
void setup() {
52-
5351
TestMessageChannelDestinationResolver resolver = new TestMessageChannelDestinationResolver();
54-
55-
this.myChannel = new ExecutorSubscribableChannel();
5652
resolver.registerMessageChannel("myChannel", this.myChannel);
57-
58-
this.template = new TestDestinationResolvingMessagingTemplate();
5953
this.template.setDestinationResolver(resolver);
60-
61-
this.headers = Collections.singletonMap("key", "value");
62-
63-
this.postProcessor = new TestMessagePostProcessor();
6454
}
6555

6656

@@ -76,8 +66,8 @@ void send() {
7666
@Test
7767
void sendNoDestinationResolver() {
7868
TestDestinationResolvingMessagingTemplate template = new TestDestinationResolvingMessagingTemplate();
79-
assertThatIllegalStateException().isThrownBy(() ->
80-
template.send("myChannel", new GenericMessage<>("payload")));
69+
assertThatIllegalStateException()
70+
.isThrownBy(() -> template.send("myChannel", new GenericMessage<>("payload")));
8171
}
8272

8373
@Test
@@ -240,19 +230,21 @@ protected Message<?> doSendAndReceive(MessageChannel channel, Message<?> request
240230
}
241231
}
242232

243-
}
244233

245-
class TestMessageChannelDestinationResolver implements DestinationResolver<MessageChannel> {
234+
private static class TestMessageChannelDestinationResolver implements DestinationResolver<MessageChannel> {
246235

247-
private final Map<String, MessageChannel> channels = new HashMap<>();
236+
private final Map<String, MessageChannel> channels = new HashMap<>();
248237

249238

250-
public void registerMessageChannel(String name, MessageChannel channel) {
251-
this.channels.put(name, channel);
252-
}
239+
public void registerMessageChannel(String name, MessageChannel channel) {
240+
this.channels.put(name, channel);
241+
}
242+
243+
@Override
244+
public MessageChannel resolveDestination(String name) throws DestinationResolutionException {
245+
return this.channels.get(name);
246+
}
253247

254-
@Override
255-
public MessageChannel resolveDestination(String name) throws DestinationResolutionException {
256-
return this.channels.get(name);
257248
}
249+
258250
}

spring-messaging/src/test/java/org/springframework/messaging/core/MessageSendingTemplateTests.java

Lines changed: 11 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2024 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -21,13 +21,12 @@
2121
import java.util.List;
2222
import java.util.Map;
2323

24-
import org.junit.jupiter.api.BeforeEach;
2524
import org.junit.jupiter.api.Test;
2625

2726
import org.springframework.messaging.Message;
2827
import org.springframework.messaging.MessageHeaders;
2928
import org.springframework.messaging.converter.CompositeMessageConverter;
30-
import org.springframework.messaging.converter.MappingJackson2MessageConverter;
29+
import org.springframework.messaging.converter.JacksonJsonMessageConverter;
3130
import org.springframework.messaging.converter.MessageConversionException;
3231
import org.springframework.messaging.converter.MessageConverter;
3332
import org.springframework.messaging.converter.StringMessageConverter;
@@ -47,21 +46,15 @@
4746
*/
4847
class MessageSendingTemplateTests {
4948

50-
private TestMessageSendingTemplate template;
49+
private final TestMessageSendingTemplate template = new TestMessageSendingTemplate();
5150

52-
private TestMessagePostProcessor postProcessor;
51+
private final TestMessagePostProcessor postProcessor = new TestMessagePostProcessor();
5352

54-
private Map<String, Object> headers;
53+
private final Map<String, Object> headers = new HashMap<>() {{
54+
put("key", "value");
55+
}};
5556

5657

57-
@BeforeEach
58-
void setup() {
59-
this.template = new TestMessageSendingTemplate();
60-
this.postProcessor = new TestMessagePostProcessor();
61-
this.headers = new HashMap<>();
62-
this.headers.put("key", "value");
63-
}
64-
6558
@Test
6659
void send() {
6760
Message<?> message = new GenericMessage<Object>("payload");
@@ -84,8 +77,7 @@ void sendToDestination() {
8477
@Test
8578
void sendMissingDestination() {
8679
Message<?> message = new GenericMessage<Object>("payload");
87-
assertThatIllegalStateException().isThrownBy(() ->
88-
this.template.send(message));
80+
assertThatIllegalStateException().isThrownBy(() -> this.template.send(message));
8981
}
9082

9183
@Test
@@ -177,14 +169,12 @@ void convertAndSendPayloadWithPostProcessorToDestination() {
177169

178170
@Test
179171
void convertAndSendNoMatchingConverter() {
180-
181-
MessageConverter converter = new CompositeMessageConverter(
182-
List.of(new MappingJackson2MessageConverter()));
172+
MessageConverter converter = new CompositeMessageConverter(List.of(new JacksonJsonMessageConverter()));
183173
this.template.setMessageConverter(converter);
184174

185175
this.headers.put(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.APPLICATION_XML);
186-
assertThatExceptionOfType(MessageConversionException.class).isThrownBy(() ->
187-
this.template.convertAndSend("home", "payload", new MessageHeaders(this.headers)));
176+
assertThatExceptionOfType(MessageConversionException.class)
177+
.isThrownBy(() -> this.template.convertAndSend("home", "payload", new MessageHeaders(this.headers)));
188178
}
189179

190180

@@ -202,19 +192,3 @@ protected void doSend(String destination, Message<?> message) {
202192
}
203193

204194
}
205-
206-
class TestMessagePostProcessor implements MessagePostProcessor {
207-
208-
private Message<?> message;
209-
210-
211-
Message<?> getMessage() {
212-
return this.message;
213-
}
214-
215-
@Override
216-
public Message<?> postProcessMessage(Message<?> message) {
217-
this.message = message;
218-
return message;
219-
}
220-
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright 2002-2025 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.messaging.core;
18+
19+
import org.springframework.messaging.Message;
20+
21+
public class TestMessagePostProcessor implements MessagePostProcessor {
22+
23+
private Message<?> message;
24+
25+
26+
Message<?> getMessage() {
27+
return this.message;
28+
}
29+
30+
@Override
31+
public Message<?> postProcessMessage(Message<?> message) {
32+
this.message = message;
33+
return message;
34+
}
35+
36+
}

spring-messaging/src/test/java/org/springframework/messaging/handler/annotation/support/MessageMethodArgumentResolverTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2024 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -218,6 +218,7 @@ void resolveWithConversionEmptyPayloadButNoConverter() {
218218
}
219219

220220
@Test // SPR-16486
221+
@SuppressWarnings("removal")
221222
public void resolveWithJacksonConverter() throws Exception {
222223
Message<String> inMessage = MessageBuilder.withPayload("{\"foo\":\"bar\"}").build();
223224
MethodParameter parameter = new MethodParameter(this.method, 5);

spring-test/src/test/java/org/springframework/test/web/servlet/samples/context/XmlConfigTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2024 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/ViewResolutionTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

spring-web/src/main/java/org/springframework/http/codec/cbor/JacksonCborDecoder.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@
3131
import org.springframework.util.MimeType;
3232

3333
/**
34-
* Decode bytes into CBOR and convert to Object's with Jackson 3.x.
35-
* Stream decoding is not supported yet.
34+
* Decode bytes into CBOR and convert to Objects with Jackson 3.x.
35+
*
36+
* <p>Stream decoding is currently not supported.
3637
*
3738
* @author Sebastien Deleuze
3839
* @since 7.0
@@ -70,7 +71,8 @@ public JacksonCborDecoder(CBORMapper mapper, MimeType... mimeTypes) {
7071
@Override
7172
public Flux<Object> decode(Publisher<DataBuffer> input, ResolvableType elementType, @Nullable MimeType mimeType,
7273
@Nullable Map<String, Object> hints) {
73-
throw new UnsupportedOperationException("Does not support stream decoding yet");
74+
75+
throw new UnsupportedOperationException("Stream decoding is currently not supported");
7476
}
7577

7678
}

spring-web/src/main/java/org/springframework/http/codec/cbor/JacksonCborEncoder.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@
3333

3434
/**
3535
* Encode from an {@code Object} to bytes of CBOR objects using Jackson 3.x.
36-
* Stream encoding is not supported yet.
36+
*
37+
* <p>Stream encoding is currently not supported.
3738
*
3839
* @author Sebastien Deleuze
3940
* @since 7.0
@@ -73,7 +74,8 @@ public JacksonCborEncoder(CBORMapper mapper, MimeType... mimeTypes) {
7374
@Override
7475
public Flux<DataBuffer> encode(Publisher<?> inputStream, DataBufferFactory bufferFactory, ResolvableType elementType,
7576
@Nullable MimeType mimeType, @Nullable Map<String, Object> hints) {
76-
throw new UnsupportedOperationException("Does not support stream encoding yet");
77+
78+
throw new UnsupportedOperationException("Stream encoding is currently not supported");
7779
}
7880

7981
}

spring-web/src/main/java/org/springframework/http/codec/smile/JacksonSmileDecoder.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import org.springframework.util.MimeType;
2424

2525
/**
26-
* Decode a byte stream into Smile and convert to Object's with Jackson 3.x,
26+
* Decode a byte stream into Smile and convert to Objects with Jackson 3.x,
2727
* leveraging non-blocking parsing.
2828
*
2929
* <p>The default constructor loads {@link tools.jackson.databind.JacksonModule}s
@@ -39,6 +39,7 @@ public class JacksonSmileDecoder extends AbstractJacksonDecoder {
3939
new MimeType("application", "x-jackson-smile"),
4040
new MimeType("application", "*+x-jackson-smile")};
4141

42+
4243
/**
4344
* Construct a new instance with a {@link SmileMapper} customized with the
4445
* {@link tools.jackson.databind.JacksonModule}s found by

spring-web/src/main/java/org/springframework/http/codec/smile/JacksonSmileEncoder.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@
3030

3131
/**
3232
* Encode from an {@code Object} stream to a byte stream of Smile objects using Jackson 3.x.
33-
* For non-streaming use cases, {@link Flux} elements are collected into a {@link List}
34-
* before serialization for performance reason.
33+
*
34+
* <p>For non-streaming use cases, {@link Flux} elements are collected into a {@link List}
35+
* before serialization for performance reasons.
3536
*
3637
* <p>The default constructor loads {@link tools.jackson.databind.JacksonModule}s
3738
* found by {@link MapperBuilder#findModules(ClassLoader)}.
@@ -98,4 +99,5 @@ public JacksonSmileEncoder(SmileMapper mapper, MimeType... mimeTypes) {
9899
}
99100
return null;
100101
}
102+
101103
}

0 commit comments

Comments
 (0)