Skip to content

Commit fff38bd

Browse files
committed
GH-1237 Add TRACE level logging to JacksonMapper
While we expect failures in individual converters and delegate to others in the stack, this enhancement will allow users to enabel TRACE level logging on failures during 'writeValueAsBytes' in JacksonMapper. Resolves #1237
1 parent fe22cb5 commit fff38bd

File tree

1 file changed

+9
-2
lines changed
  • spring-cloud-function-context/src/main/java/org/springframework/cloud/function/json

1 file changed

+9
-2
lines changed

spring-cloud-function-context/src/main/java/org/springframework/cloud/function/json/JacksonMapper.java

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2025 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.
@@ -25,13 +25,18 @@
2525
import com.fasterxml.jackson.databind.JavaType;
2626
import com.fasterxml.jackson.databind.ObjectMapper;
2727
import com.fasterxml.jackson.databind.type.TypeFactory;
28+
import org.apache.commons.logging.Log;
29+
import org.apache.commons.logging.LogFactory;
30+
2831

2932
/**
3033
* @author Dave Syer
3134
* @author Oleg Zhurakousky
3235
*/
3336
public class JacksonMapper extends JsonMapper {
3437

38+
private static Log logger = LogFactory.getLog(JacksonMapper.class);
39+
3540
private final ObjectMapper mapper;
3641

3742
public JacksonMapper(ObjectMapper mapper) {
@@ -75,7 +80,9 @@ public byte[] toJson(Object value) {
7580
jsonBytes = this.mapper.writeValueAsBytes(value);
7681
}
7782
catch (Exception e) {
78-
//ignore and let other converters have a chance
83+
if (logger.isTraceEnabled()) {
84+
logger.trace("Failed to writeValueAsBytes: " + value, e);
85+
}
7986
}
8087
}
8188
return jsonBytes;

0 commit comments

Comments
 (0)