在我的Spring MVC Rest控制器方法中,我试图在另一个名为HttpSession
的自定义对象中返回一个Token
对象,所有这些对象都在Spring ResponseEntity
对象中,返回客户。
但出于某种原因,每当我将Stackoverflow
对象包含为Jackson
时,由于某些无限递归 HttpSession
数据绑定问题,我收到Token
错误我的StackOverflow
课程中的一个属性。
我的HttpSession
课程中Token
对象不时,我没有收到Token
错误。
这是我的public class Token implements Serializable {
private static final long serialVersionUID = 1L;
private HttpSession session;
private String value;
public Token () {}
public Token (HttpSession session, String value) {
this.session = session;
this.value = value;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public HttpSession getSession() {
return session;
}
public void setSession(HttpSession session) {
this.session = session;
}
}
课程:
@RequestMapping(value = "/getData", method = RequestMethod.GET)
public ResponseEntity<Token> getData(HttpServletRequest request) {
HttpSession session = request.getSession();
Token t = new Token(session, "value");
return new ResponseEntity<Token>(t, HttpStatus.OK);
}
这是我的控制器方法:
Root cause of ServletException. org.springframework.http.converter.HttpMessageNotWritableException: Could not write JSON: Infinite recursion (StackOverflowError); nested exception is com.fasterxml.jackson.databind.JsonMappingException: Infinite recursion (StackOverflowError) (through reference chain: weblogic.servlet.internal.WebAppServletContext["securityContext"]->weblogic.servlet.internal.ServletSecurityContextImpl["servletContext"]............... com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:155) at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:727) at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:719) at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:155) at ........-
任何人都知道为什么会这样吗?
这是堆栈跟踪:
BeautifulSoup