Browse Source

Merge branch '5.3.x'

pull/29066/head
Sébastien Deleuze 2 years ago
parent
commit
7214b1e03c
  1. 6
      spring-messaging/src/main/java/org/springframework/messaging/simp/config/AbstractMessageBrokerConfiguration.java
  2. 11
      spring-messaging/src/test/java/org/springframework/messaging/simp/config/MessageBrokerConfigurationTests.java
  3. 6
      spring-web/src/main/java/org/springframework/http/converter/support/AllEncompassingFormHttpMessageConverter.java
  4. 6
      spring-web/src/main/java/org/springframework/web/client/RestTemplate.java
  5. 12
      spring-web/src/test/java/org/springframework/web/client/RestTemplateTests.java

6
spring-messaging/src/main/java/org/springframework/messaging/simp/config/AbstractMessageBrokerConfiguration.java

@ -465,6 +465,9 @@ public abstract class AbstractMessageBrokerConfiguration implements ApplicationC @@ -465,6 +465,9 @@ public abstract class AbstractMessageBrokerConfiguration implements ApplicationC
if (registerDefaults) {
converters.add(new StringMessageConverter());
converters.add(new ByteArrayMessageConverter());
if (kotlinSerializationJsonPresent) {
converters.add(new KotlinSerializationJsonMessageConverter());
}
if (jackson2Present) {
converters.add(createJacksonConverter());
}
@ -474,9 +477,6 @@ public abstract class AbstractMessageBrokerConfiguration implements ApplicationC @@ -474,9 +477,6 @@ public abstract class AbstractMessageBrokerConfiguration implements ApplicationC
else if (jsonbPresent) {
converters.add(new JsonbMessageConverter());
}
else if (kotlinSerializationJsonPresent) {
converters.add(new KotlinSerializationJsonMessageConverter());
}
}
return new CompositeMessageConverter(converters);
}

11
spring-messaging/src/test/java/org/springframework/messaging/simp/config/MessageBrokerConfigurationTests.java

@ -39,6 +39,7 @@ import org.springframework.messaging.converter.ByteArrayMessageConverter; @@ -39,6 +39,7 @@ import org.springframework.messaging.converter.ByteArrayMessageConverter;
import org.springframework.messaging.converter.CompositeMessageConverter;
import org.springframework.messaging.converter.ContentTypeResolver;
import org.springframework.messaging.converter.DefaultContentTypeResolver;
import org.springframework.messaging.converter.KotlinSerializationJsonMessageConverter;
import org.springframework.messaging.converter.MappingJackson2MessageConverter;
import org.springframework.messaging.converter.MessageConverter;
import org.springframework.messaging.converter.StringMessageConverter;
@ -282,12 +283,13 @@ public class MessageBrokerConfigurationTests { @@ -282,12 +283,13 @@ public class MessageBrokerConfigurationTests {
CompositeMessageConverter compositeConverter = config.brokerMessageConverter();
List<MessageConverter> converters = compositeConverter.getConverters();
assertThat(converters).hasSize(3);
assertThat(converters).hasSize(4);
assertThat(converters.get(0)).isInstanceOf(StringMessageConverter.class);
assertThat(converters.get(1)).isInstanceOf(ByteArrayMessageConverter.class);
assertThat(converters.get(2)).isInstanceOf(MappingJackson2MessageConverter.class);
assertThat(converters.get(2)).isInstanceOf(KotlinSerializationJsonMessageConverter.class);
assertThat(converters.get(3)).isInstanceOf(MappingJackson2MessageConverter.class);
ContentTypeResolver resolver = ((MappingJackson2MessageConverter) converters.get(2)).getContentTypeResolver();
ContentTypeResolver resolver = ((MappingJackson2MessageConverter) converters.get(3)).getContentTypeResolver();
assertThat(((DefaultContentTypeResolver) resolver).getDefaultMimeType()).isEqualTo(MimeTypeUtils.APPLICATION_JSON);
}
@ -340,11 +342,12 @@ public class MessageBrokerConfigurationTests { @@ -340,11 +342,12 @@ public class MessageBrokerConfigurationTests {
};
CompositeMessageConverter compositeConverter = config.brokerMessageConverter();
assertThat(compositeConverter.getConverters()).hasSize(4);
assertThat(compositeConverter.getConverters()).hasSize(5);
Iterator<MessageConverter> iterator = compositeConverter.getConverters().iterator();
assertThat(iterator.next()).isEqualTo(testConverter);
assertThat(iterator.next()).isInstanceOf(StringMessageConverter.class);
assertThat(iterator.next()).isInstanceOf(ByteArrayMessageConverter.class);
assertThat(iterator.next()).isInstanceOf(KotlinSerializationJsonMessageConverter.class);
assertThat(iterator.next()).isInstanceOf(MappingJackson2MessageConverter.class);
}

6
spring-web/src/main/java/org/springframework/http/converter/support/AllEncompassingFormHttpMessageConverter.java

@ -87,6 +87,9 @@ public class AllEncompassingFormHttpMessageConverter extends FormHttpMessageConv @@ -87,6 +87,9 @@ public class AllEncompassingFormHttpMessageConverter extends FormHttpMessageConv
}
}
if (kotlinSerializationJsonPresent) {
addPartConverter(new KotlinSerializationJsonHttpMessageConverter());
}
if (jackson2Present) {
addPartConverter(new MappingJackson2HttpMessageConverter());
}
@ -96,9 +99,6 @@ public class AllEncompassingFormHttpMessageConverter extends FormHttpMessageConv @@ -96,9 +99,6 @@ public class AllEncompassingFormHttpMessageConverter extends FormHttpMessageConv
else if (jsonbPresent) {
addPartConverter(new JsonbHttpMessageConverter());
}
else if (kotlinSerializationJsonPresent) {
addPartConverter(new KotlinSerializationJsonHttpMessageConverter());
}
if (jackson2XmlPresent && !shouldIgnoreXml) {
addPartConverter(new MappingJackson2XmlHttpMessageConverter());

6
spring-web/src/main/java/org/springframework/web/client/RestTemplate.java

@ -175,6 +175,9 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat @@ -175,6 +175,9 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat
}
}
if (kotlinSerializationJsonPresent) {
this.messageConverters.add(new KotlinSerializationJsonHttpMessageConverter());
}
if (jackson2Present) {
this.messageConverters.add(new MappingJackson2HttpMessageConverter());
}
@ -184,9 +187,6 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat @@ -184,9 +187,6 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat
else if (jsonbPresent) {
this.messageConverters.add(new JsonbHttpMessageConverter());
}
else if (kotlinSerializationJsonPresent) {
this.messageConverters.add(new KotlinSerializationJsonHttpMessageConverter());
}
if (jackson2SmilePresent) {
this.messageConverters.add(new MappingJackson2SmileHttpMessageConverter());

12
spring-web/src/test/java/org/springframework/web/client/RestTemplateTests.java

@ -50,6 +50,8 @@ import org.springframework.http.client.ClientHttpResponse; @@ -50,6 +50,8 @@ import org.springframework.http.client.ClientHttpResponse;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.http.converter.GenericHttpMessageConverter;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.KotlinSerializationJsonHttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.util.StreamUtils;
import org.springframework.web.util.DefaultUriBuilderFactory;
@ -102,6 +104,16 @@ class RestTemplateTests { @@ -102,6 +104,16 @@ class RestTemplateTests {
template.setErrorHandler(errorHandler);
}
@Test // gh-29008
void defaultMessageConvertersWithKotlinSerialization() {
RestTemplate restTemplate = new RestTemplate();
List<HttpMessageConverter<?>> httpMessageConverters = restTemplate.getMessageConverters();
assertThat(httpMessageConverters).extracting("class").containsOnlyOnce(
KotlinSerializationJsonHttpMessageConverter.class,
MappingJackson2HttpMessageConverter.class
);
}
@Test
void constructorPreconditions() {
assertThatIllegalArgumentException()

Loading…
Cancel
Save