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
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2025 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -25,6 +25,9 @@ import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.JavaType;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.type.TypeFactory;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
@@ -32,6 +35,8 @@ import com.fasterxml.jackson.databind.type.TypeFactory;
|
||||
*/
|
||||
public class JacksonMapper extends JsonMapper {
|
||||
|
||||
private static Log logger = LogFactory.getLog(JacksonMapper.class);
|
||||
|
||||
private final ObjectMapper mapper;
|
||||
|
||||
public JacksonMapper(ObjectMapper mapper) {
|
||||
@@ -75,7 +80,9 @@ public class JacksonMapper extends JsonMapper {
|
||||
jsonBytes = this.mapper.writeValueAsBytes(value);
|
||||
}
|
||||
catch (Exception e) {
|
||||
//ignore and let other converters have a chance
|
||||
if (logger.isTraceEnabled()) {
|
||||
logger.trace("Failed to writeValueAsBytes: " + value, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
return jsonBytes;
|
||||
|
||||
Reference in New Issue
Block a user