Skip to content

Commit bf3cadb

Browse files
committed
AbstractJackson2HttpMessageConverter's canRead/canWrite checks media type first before delegating to Jackson
Issue: SPR-14163 (cherry picked from commit e366746)
1 parent 863bae7 commit bf3cadb

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

spring-web/src/main/java/org/springframework/http/converter/json/AbstractJackson2HttpMessageConverter.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,14 @@ public boolean canRead(Class<?> clazz, MediaType mediaType) {
145145
@Override
146146
public boolean canRead(Type type, Class<?> contextClass, MediaType mediaType) {
147147
JavaType javaType = getJavaType(type, contextClass);
148+
if (!canRead(mediaType)) {
149+
return false;
150+
}
148151
if (!jackson23Available || !logger.isWarnEnabled()) {
149-
return (this.objectMapper.canDeserialize(javaType) && canRead(mediaType));
152+
return this.objectMapper.canDeserialize(javaType);
150153
}
151154
AtomicReference<Throwable> causeRef = new AtomicReference<Throwable>();
152-
if (this.objectMapper.canDeserialize(javaType, causeRef) && canRead(mediaType)) {
155+
if (this.objectMapper.canDeserialize(javaType, causeRef)) {
153156
return true;
154157
}
155158
Throwable cause = causeRef.get();
@@ -167,11 +170,14 @@ public boolean canRead(Type type, Class<?> contextClass, MediaType mediaType) {
167170

168171
@Override
169172
public boolean canWrite(Class<?> clazz, MediaType mediaType) {
173+
if (!canWrite(mediaType)) {
174+
return false;
175+
}
170176
if (!jackson23Available || !logger.isWarnEnabled()) {
171-
return (this.objectMapper.canSerialize(clazz) && canWrite(mediaType));
177+
return this.objectMapper.canSerialize(clazz);
172178
}
173179
AtomicReference<Throwable> causeRef = new AtomicReference<Throwable>();
174-
if (this.objectMapper.canSerialize(clazz, causeRef) && canWrite(mediaType)) {
180+
if (this.objectMapper.canSerialize(clazz, causeRef)) {
175181
return true;
176182
}
177183
Throwable cause = causeRef.get();

0 commit comments

Comments
 (0)