Skip to content

Commit be93ee7

Browse files
committed
Debug-level log entry for any Jackson exception during canConvert
Issue: SPR-15582
1 parent 8330134 commit be93ee7

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

spring-messaging/src/main/java/org/springframework/messaging/converter/MappingJackson2MessageConverter.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2017 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.
@@ -178,10 +178,20 @@ protected boolean canConvertTo(Object payload, MessageHeaders headers) {
178178
* @since 4.3
179179
*/
180180
protected void logWarningIfNecessary(Type type, Throwable cause) {
181-
if (cause != null && !(cause instanceof JsonMappingException && cause.getMessage().startsWith("Can not find"))) {
181+
if (cause == null) {
182+
return;
183+
}
184+
185+
boolean debugLevel = (cause instanceof JsonMappingException &&
186+
cause.getMessage().startsWith("Can not find"));
187+
188+
if (debugLevel ? logger.isDebugEnabled() : logger.isWarnEnabled()) {
182189
String msg = "Failed to evaluate Jackson " + (type instanceof JavaType ? "de" : "") +
183190
"serialization for type [" + type + "]";
184-
if (logger.isDebugEnabled()) {
191+
if (debugLevel) {
192+
logger.debug(msg, cause);
193+
}
194+
else if (logger.isDebugEnabled()) {
185195
logger.warn(msg, cause);
186196
}
187197
else {

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,20 @@ public boolean canWrite(Class<?> clazz, MediaType mediaType) {
191191
* @since 4.3
192192
*/
193193
protected void logWarningIfNecessary(Type type, Throwable cause) {
194-
if (cause != null && !(cause instanceof JsonMappingException && cause.getMessage().startsWith("Can not find"))) {
194+
if (cause == null) {
195+
return;
196+
}
197+
198+
boolean debugLevel = (cause instanceof JsonMappingException &&
199+
cause.getMessage().startsWith("Can not find"));
200+
201+
if (debugLevel ? logger.isDebugEnabled() : logger.isWarnEnabled()) {
195202
String msg = "Failed to evaluate Jackson " + (type instanceof JavaType ? "de" : "") +
196203
"serialization for type [" + type + "]";
197-
if (logger.isDebugEnabled()) {
204+
if (debugLevel) {
205+
logger.debug(msg, cause);
206+
}
207+
else if (logger.isDebugEnabled()) {
198208
logger.warn(msg, cause);
199209
}
200210
else {

0 commit comments

Comments
 (0)