File tree Expand file tree Collapse file tree 6 files changed +31
-26
lines changed
spring-core/src/main/java/org/springframework/util
spring-web/src/main/java/org/springframework/http Expand file tree Collapse file tree 6 files changed +31
-26
lines changed Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2002-2022 the original author or authors.
2
+ * Copyright 2002-2023 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -268,7 +268,8 @@ public boolean isWildcardType() {
268
268
* @return whether the subtype is a wildcard
269
269
*/
270
270
public boolean isWildcardSubtype () {
271
- return WILDCARD_TYPE .equals (getSubtype ()) || getSubtype ().startsWith ("*+" );
271
+ String subtype = getSubtype ();
272
+ return WILDCARD_TYPE .equals (subtype ) || subtype .startsWith ("*+" );
272
273
}
273
274
274
275
/**
Original file line number Diff line number Diff line change @@ -181,7 +181,7 @@ public abstract class MimeTypeUtils {
181
181
182
182
static {
183
183
// Not using "parseMimeType" to avoid static init cost
184
- ALL = new MimeType ("*" , "*" );
184
+ ALL = new MimeType (MimeType . WILDCARD_TYPE , MimeType . WILDCARD_TYPE );
185
185
APPLICATION_GRAPHQL = new MimeType ("application" , "graphql+json" );
186
186
APPLICATION_JSON = new MimeType ("application" , "json" );
187
187
APPLICATION_OCTET_STREAM = new MimeType ("application" , "octet-stream" );
Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2002-2022 the original author or authors.
2
+ * Copyright 2002-2023 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -435,7 +435,7 @@ public class MediaType extends MimeType implements Serializable {
435
435
436
436
static {
437
437
// Not using "valueOf' to avoid static init cost
438
- ALL = new MediaType ("*" , "*" );
438
+ ALL = new MediaType (MimeType . WILDCARD_TYPE , MimeType . WILDCARD_TYPE );
439
439
APPLICATION_ATOM_XML = new MediaType ("application" , "atom+xml" );
440
440
APPLICATION_CBOR = new MediaType ("application" , "cbor" );
441
441
APPLICATION_FORM_URLENCODED = new MediaType ("application" , "x-www-form-urlencoded" );
Original file line number Diff line number Diff line change @@ -104,12 +104,14 @@ public int getMaxInMemorySize() {
104
104
105
105
@ Override
106
106
public boolean canRead (ResolvableType elementType , @ Nullable MediaType mediaType ) {
107
- boolean multiValueUnresolved =
108
- elementType .hasUnresolvableGenerics () &&
109
- MultiValueMap .class .isAssignableFrom (elementType .toClass ());
110
-
111
- return ((MULTIVALUE_STRINGS_TYPE .isAssignableFrom (elementType ) || multiValueUnresolved ) &&
112
- (mediaType == null || MediaType .APPLICATION_FORM_URLENCODED .isCompatibleWith (mediaType )));
107
+ if (mediaType == null || MediaType .APPLICATION_FORM_URLENCODED .isCompatibleWith (mediaType )) {
108
+ if (MultiValueMap .class .isAssignableFrom (elementType .toClass ()) &&
109
+ elementType .hasUnresolvableGenerics ()) {
110
+ return true ;
111
+ }
112
+ return MULTIVALUE_STRINGS_TYPE .isAssignableFrom (elementType );
113
+ }
114
+ return false ;
113
115
}
114
116
115
117
@ Override
Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2002-2022 the original author or authors.
2
+ * Copyright 2002-2023 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -97,15 +97,15 @@ public int getMaxInMemorySize() {
97
97
98
98
@ Override
99
99
public boolean canDecode (ResolvableType elementType , @ Nullable MimeType mimeType ) {
100
+ // Skip String: CharSequenceDecoder + "*/*" comes after
101
+ if (CharSequence .class .isAssignableFrom (elementType .toClass ()) || !supportsMimeType (mimeType )) {
102
+ return false ;
103
+ }
100
104
ObjectMapper mapper = selectObjectMapper (elementType , mimeType );
101
105
if (mapper == null ) {
102
106
return false ;
103
107
}
104
108
JavaType javaType = mapper .constructType (elementType .getType ());
105
- // Skip String: CharSequenceDecoder + "*/*" comes after
106
- if (CharSequence .class .isAssignableFrom (elementType .toClass ()) || !supportsMimeType (mimeType )) {
107
- return false ;
108
- }
109
109
if (!logger .isDebugEnabled ()) {
110
110
return mapper .canDeserialize (javaType );
111
111
}
Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2002-2022 the original author or authors.
2
+ * Copyright 2002-2023 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -81,21 +81,23 @@ public List<MediaType> getReadableMediaTypes() {
81
81
return MIME_TYPES ;
82
82
}
83
83
84
- @ Override
85
- public boolean canRead (ResolvableType elementType , @ Nullable MediaType mediaType ) {
86
- if (MULTIPART_VALUE_TYPE .isAssignableFrom (elementType )) {
87
- if (mediaType == null ) {
84
+ private boolean supportsMediaType (@ Nullable MediaType mediaType ) {
85
+ if (mediaType == null ) {
86
+ return true ;
87
+ }
88
+ for (MediaType supportedMediaType : MIME_TYPES ) {
89
+ if (supportedMediaType .isCompatibleWith (mediaType )) {
88
90
return true ;
89
91
}
90
- for (MediaType supportedMediaType : MIME_TYPES ) {
91
- if (supportedMediaType .isCompatibleWith (mediaType )) {
92
- return true ;
93
- }
94
- }
95
92
}
96
93
return false ;
97
94
}
98
95
96
+ @ Override
97
+ public boolean canRead (ResolvableType elementType , @ Nullable MediaType mediaType ) {
98
+ return supportsMediaType (mediaType ) && MULTIPART_VALUE_TYPE .isAssignableFrom (elementType );
99
+ }
100
+
99
101
100
102
@ Override
101
103
public Flux <MultiValueMap <String , Part >> read (ResolvableType elementType ,
You can’t perform that action at this time.
0 commit comments