Skip to content

Add constants for application/cbor to MediaType #23042

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions spring-web/src/main/java/org/springframework/http/MediaType.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,18 @@ public class MediaType extends MimeType implements Serializable {
*/
public static final String APPLICATION_ATOM_XML_VALUE = "application/atom+xml";

/**
* Public constant media type for {@code application/cbor}.
* @since 5.2
*/
public static final MediaType APPLICATION_CBOR;

/**
* A String equivalent of {@link MediaType#APPLICATION_CBOR}.
* @since 5.2
*/
public static final String APPLICATION_CBOR_VALUE = "application/cbor";

/**
* Public constant media type for {@code application/x-www-form-urlencoded}.
*/
Expand Down Expand Up @@ -338,6 +350,7 @@ public class MediaType extends MimeType implements Serializable {
// Not using "valueOf' to avoid static init cost
ALL = new MediaType("*", "*");
APPLICATION_ATOM_XML = new MediaType("application", "atom+xml");
APPLICATION_CBOR = new MediaType("application", "cbor");
APPLICATION_FORM_URLENCODED = new MediaType("application", "x-www-form-urlencoded");
APPLICATION_JSON = new MediaType("application", "json");
APPLICATION_JSON_UTF8 = new MediaType("application", "json", StandardCharsets.UTF_8);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
public class Jackson2CborDecoder extends AbstractJackson2Decoder {

public Jackson2CborDecoder() {
this(Jackson2ObjectMapperBuilder.cbor().build(), new MediaType("application", "cbor"));
this(Jackson2ObjectMapperBuilder.cbor().build(), MediaType.APPLICATION_CBOR);
}

public Jackson2CborDecoder(ObjectMapper mapper, MimeType... mimeTypes) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
public class Jackson2CborEncoder extends AbstractJackson2Encoder {

public Jackson2CborEncoder() {
this(Jackson2ObjectMapperBuilder.cbor().build(), new MediaType("application", "cbor"));
this(Jackson2ObjectMapperBuilder.cbor().build(), MediaType.APPLICATION_CBOR);
}

public Jackson2CborEncoder(ObjectMapper mapper, MimeType... mimeTypes) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* <a href="https://github.com/FasterXML/jackson-dataformats-binary/tree/master/cbor">
* the dedicated Jackson 2.x extension</a>.
*
* <p>By default, this converter supports {@code "application/cbor"} media type. This can be
* <p>By default, this converter supports {@value MediaType#APPLICATION_CBOR_VALUE} media type. This can be
* overridden by setting the {@link #setSupportedMediaTypes supportedMediaTypes} property.
*
* <p>The default constructor uses the default configuration provided by {@link Jackson2ObjectMapperBuilder}.
Expand All @@ -57,7 +57,7 @@ public MappingJackson2CborHttpMessageConverter() {
* @see Jackson2ObjectMapperBuilder#cbor()
*/
public MappingJackson2CborHttpMessageConverter(ObjectMapper objectMapper) {
super(objectMapper, new MediaType("application", "cbor"));
super(objectMapper, MediaType.APPLICATION_CBOR);
Assert.isInstanceOf(CBORFactory.class, objectMapper.getFactory(), "CBORFactory required");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ private Properties getDefaultMediaTypes() {
defaultMediaTypes.put("smile", "application/x-jackson-smile");
}
if (jackson2CborPresent) {
defaultMediaTypes.put("cbor", "application/cbor");
defaultMediaTypes.put("cbor", MediaType.APPLICATION_CBOR_VALUE);
}
return defaultMediaTypes;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ protected Map<String, MediaType> getDefaultMediaTypes() {
map.put("smile", MediaType.valueOf("application/x-jackson-smile"));
}
if (jackson2CborPresent) {
map.put("cbor", MediaType.valueOf("application/cbor"));
map.put("cbor", MediaType.APPLICATION_CBOR);
}
return map;
}
Expand Down