[英]How to use Jackson serialization on toString method?
I have already set up an exposed entity class through Jackson
serialisation, which works well in my RestController
. 我已经通过Jackson
序列化设置了一个公开的实体类,它在我的RestController
运行良好。
Recently, I tried to create a Spring AOP
to display the log, but it uses toString
of the class, which throws StackOverflow
exception since the class contains a bi-directional relationship. 最近,我尝试创建一个Spring AOP
来显示日志,但是它使用了类的toString
,它抛出了StackOverflow
异常,因为该类包含双向关系。
Object result = joinPoint.proceed();
if (log.isDebugEnabled()) {
log.debug("Exit: {}.{}() with result = {}",
joinPoint.getSignature().getDeclaringTypeName(),
joinPoint.getSignature().getName(),
result);
}
How do I set up the toString
method to use already configured Jackson
serialisation? 如何设置toString
方法以使用已配置的Jackson
序列化?
I solved my problem by using ObjectMapper
. 我通过使用ObjectMapper
解决了我的问题。
Object result = joinPoint.proceed();
if (log.isDebugEnabled()) {
log.debug("Exit: {}.{}() with result = {}",
joinPoint.getSignature().getDeclaringTypeName(),
joinPoint.getSignature().getName(),
new ObjectMapper().writeValueAsString(result));
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.