Skip to content

Commit d104ee1

Browse files
committed
Add constants for application/cbor to MediaType
1 parent bc205e0 commit d104ee1

File tree

6 files changed

+19
-6
lines changed

6 files changed

+19
-6
lines changed

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,18 @@ public class MediaType extends MimeType implements Serializable {
7373
*/
7474
public static final String APPLICATION_ATOM_XML_VALUE = "application/atom+xml";
7575

76+
/**
77+
* Public constant media type for {@code application/cbor}.
78+
* @since 5.2
79+
*/
80+
public static final MediaType APPLICATION_CBOR;
81+
82+
/**
83+
* A String equivalent of {@link MediaType#APPLICATION_CBOR}.
84+
* @since 5.2
85+
*/
86+
public static final String APPLICATION_CBOR_VALUE = "application/cbor";
87+
7688
/**
7789
* Public constant media type for {@code application/x-www-form-urlencoded}.
7890
*/
@@ -338,6 +350,7 @@ public class MediaType extends MimeType implements Serializable {
338350
// Not using "valueOf' to avoid static init cost
339351
ALL = new MediaType("*", "*");
340352
APPLICATION_ATOM_XML = new MediaType("application", "atom+xml");
353+
APPLICATION_CBOR = new MediaType("application", "cbor");
341354
APPLICATION_FORM_URLENCODED = new MediaType("application", "x-www-form-urlencoded");
342355
APPLICATION_JSON = new MediaType("application", "json");
343356
APPLICATION_JSON_UTF8 = new MediaType("application", "json", StandardCharsets.UTF_8);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
public class Jackson2CborDecoder extends AbstractJackson2Decoder {
4444

4545
public Jackson2CborDecoder() {
46-
this(Jackson2ObjectMapperBuilder.cbor().build(), new MediaType("application", "cbor"));
46+
this(Jackson2ObjectMapperBuilder.cbor().build(), MediaType.APPLICATION_CBOR);
4747
}
4848

4949
public Jackson2CborDecoder(ObjectMapper mapper, MimeType... mimeTypes) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
public class Jackson2CborEncoder extends AbstractJackson2Encoder {
4545

4646
public Jackson2CborEncoder() {
47-
this(Jackson2ObjectMapperBuilder.cbor().build(), new MediaType("application", "cbor"));
47+
this(Jackson2ObjectMapperBuilder.cbor().build(), MediaType.APPLICATION_CBOR);
4848
}
4949

5050
public Jackson2CborEncoder(ObjectMapper mapper, MimeType... mimeTypes) {

spring-web/src/main/java/org/springframework/http/converter/cbor/MappingJackson2CborHttpMessageConverter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
* <a href="https://github.com/FasterXML/jackson-dataformats-binary/tree/master/cbor">
3131
* the dedicated Jackson 2.x extension</a>.
3232
*
33-
* <p>By default, this converter supports {@code "application/cbor"} media type. This can be
33+
* <p>By default, this converter supports {@value MediaType#APPLICATION_CBOR_VALUE} media type. This can be
3434
* overridden by setting the {@link #setSupportedMediaTypes supportedMediaTypes} property.
3535
*
3636
* <p>The default constructor uses the default configuration provided by {@link Jackson2ObjectMapperBuilder}.
@@ -57,7 +57,7 @@ public MappingJackson2CborHttpMessageConverter() {
5757
* @see Jackson2ObjectMapperBuilder#cbor()
5858
*/
5959
public MappingJackson2CborHttpMessageConverter(ObjectMapper objectMapper) {
60-
super(objectMapper, new MediaType("application", "cbor"));
60+
super(objectMapper, MediaType.APPLICATION_CBOR);
6161
Assert.isInstanceOf(CBORFactory.class, objectMapper.getFactory(), "CBORFactory required");
6262
}
6363

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ private Properties getDefaultMediaTypes() {
450450
defaultMediaTypes.put("smile", "application/x-jackson-smile");
451451
}
452452
if (jackson2CborPresent) {
453-
defaultMediaTypes.put("cbor", "application/cbor");
453+
defaultMediaTypes.put("cbor", MediaType.APPLICATION_CBOR_VALUE);
454454
}
455455
return defaultMediaTypes;
456456
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ protected Map<String, MediaType> getDefaultMediaTypes() {
427427
map.put("smile", MediaType.valueOf("application/x-jackson-smile"));
428428
}
429429
if (jackson2CborPresent) {
430-
map.put("cbor", MediaType.valueOf("application/cbor"));
430+
map.put("cbor", MediaType.APPLICATION_CBOR);
431431
}
432432
return map;
433433
}

0 commit comments

Comments
 (0)