Skip to content

Commit 5ee11fb

Browse files
committed
Polish Yaml support
Closes gh-32345
1 parent 6a8f0d6 commit 5ee11fb

File tree

4 files changed

+15
-5
lines changed

4 files changed

+15
-5
lines changed

spring-web/src/main/java/org/springframework/http/MediaType.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -314,13 +314,15 @@ public class MediaType extends MimeType implements Serializable {
314314

315315
/**
316316
* Public constant media type for {@code application/yaml}.
317+
* @since 6.2
317318
*/
318319
public static final MediaType APPLICATION_YAML;
319320

320321
/**
321322
* A String equivalent of {@link MediaType#APPLICATION_YAML}.
323+
* @since 6.2
322324
*/
323-
public static final String APPLICATION_YAML_VALE = "application/yaml";
325+
public static final String APPLICATION_YAML_VALUE = "application/yaml";
324326

325327
/**
326328
* Public constant media type for {@code image/gif}.

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

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2024 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.
@@ -26,6 +26,7 @@
2626
import org.springframework.http.converter.smile.MappingJackson2SmileHttpMessageConverter;
2727
import org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter;
2828
import org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConverter;
29+
import org.springframework.http.converter.yaml.MappingJackson2YamlHttpMessageConverter;
2930
import org.springframework.util.ClassUtils;
3031

3132
/**
@@ -47,6 +48,8 @@ public class AllEncompassingFormHttpMessageConverter extends FormHttpMessageConv
4748

4849
private static final boolean jackson2SmilePresent;
4950

51+
private static final boolean jackson2YamlPresent;
52+
5053
private static final boolean gsonPresent;
5154

5255
private static final boolean jsonbPresent;
@@ -64,6 +67,7 @@ public class AllEncompassingFormHttpMessageConverter extends FormHttpMessageConv
6467
ClassUtils.isPresent("com.fasterxml.jackson.core.JsonGenerator", classLoader);
6568
jackson2XmlPresent = ClassUtils.isPresent("com.fasterxml.jackson.dataformat.xml.XmlMapper", classLoader);
6669
jackson2SmilePresent = ClassUtils.isPresent("com.fasterxml.jackson.dataformat.smile.SmileFactory", classLoader);
70+
jackson2YamlPresent = ClassUtils.isPresent("com.fasterxml.jackson.dataformat.yaml.YAMLFactory", classLoader);
6771
gsonPresent = ClassUtils.isPresent("com.google.gson.Gson", classLoader);
6872
jsonbPresent = ClassUtils.isPresent("jakarta.json.bind.Jsonb", classLoader);
6973
kotlinSerializationCborPresent = ClassUtils.isPresent("kotlinx.serialization.cbor.Cbor", classLoader);
@@ -99,6 +103,10 @@ else if (jsonbPresent) {
99103
addPartConverter(new MappingJackson2SmileHttpMessageConverter());
100104
}
101105

106+
if (jackson2YamlPresent) {
107+
addPartConverter(new MappingJackson2YamlHttpMessageConverter());
108+
}
109+
102110
if (kotlinSerializationCborPresent) {
103111
addPartConverter(new KotlinSerializationCborHttpMessageConverter());
104112
}

spring-web/src/main/java/org/springframework/http/converter/yaml/MappingJackson2YamlHttpMessageConverter.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@
2727
/**
2828
* Implementation of {@link org.springframework.http.converter.HttpMessageConverter
2929
* HttpMessageConverter} that can read and write the <a href="https://yaml.io/">YAML</a>
30-
* data format using <a href="https://github.com/FasterXML/jackson-dataformat-yaml/tree/master">
30+
* data format using <a href="https://github.com/FasterXML/jackson-dataformats-text/tree/2.17/yaml">
3131
* the dedicated Jackson 2.x extension</a>.
3232
*
33-
* <p>By default, this converter supports the {@link MediaType#APPLICATION_YAML_VALE}
33+
* <p>By default, this converter supports the {@link MediaType#APPLICATION_YAML_VALUE}
3434
* media type. This can be overridden by setting the {@link #setSupportedMediaTypes
3535
* supportedMediaTypes} property.
3636
*

spring-webmvc/src/main/java/org/springframework/web/servlet/config/AnnotationDrivenBeanDefinitionParser.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ private Properties getDefaultMediaTypes() {
470470
defaultMediaTypes.put("cbor", MediaType.APPLICATION_CBOR_VALUE);
471471
}
472472
if (jackson2YamlPresent) {
473-
defaultMediaTypes.put("yaml", MediaType.APPLICATION_YAML_VALE);
473+
defaultMediaTypes.put("yaml", MediaType.APPLICATION_YAML_VALUE);
474474
}
475475
return defaultMediaTypes;
476476
}

0 commit comments

Comments
 (0)