我已经通过Jackson
序列化设置了一个暴露的实体类,这在我的RestController
上很好用。
最近,我尝试创建一个Spring AOP
来显示日志,但是它使用了该类的toString
,由于该类包含双向关系,因此会抛出StackOverflow
异常。
Object result = joinPoint.proceed();
if (log.isDebugEnabled()) {
log.debug("Exit: {}.{}() with result = {}",
joinPoint.getSignature().getDeclaringTypeName(),
joinPoint.getSignature().getName(),
result);
}
如何设置toString
方法以使用已配置的Jackson
序列化?
答案 0 :(得分:0)
我使用ObjectMapper
解决了我的问题。
Object result = joinPoint.proceed();
if (log.isDebugEnabled()) {
log.debug("Exit: {}.{}() with result = {}",
joinPoint.getSignature().getDeclaringTypeName(),
joinPoint.getSignature().getName(),
new ObjectMapper().writeValueAsString(result));
}