devYuraKim / devYuraKim/spring

example41 - Handling Bidirectional Relationships in Jackson to Prevent Infinite Recursion

Open
#2 2 comments 0 reactions 1 assignee Claimed by @devYuraKim View on GitHub
good first issue question
Dominant language
CSS
Stars
2
Forks
1
PR merge metrics
No merged PRs in 30d

Description

I wanted to check for myself what kind of information gets stored in HttpSession, so I added in `SessionController.java`.
```
@RestController
@RequestMapping("/session")
public class SessionController {

private final HttpSession session;

@Autowired
public SessionController(HttpSession session) {
this.session = session;
}

@RequestMapping(method = RequestMethod.GET)
public Map getSessionAttributes() {
Map attributes = new HashMap<>();
Enumeration attributeNames = session.getAttributeNames();
while (attributeNames.hasMoreElements()) {
String name = attributeNames.nextElement();
attributes.put(name, session.getAttribute(name));
}
return attributes;
}
}
```

The results were nice and pretty
before

up until `session.setAttribute("eazyClass", eazyClass);` from `AdminController.java` was executed.
AdminController.java
```
@RequestMapping("/displayStudents")
public String displayStudents(Model model, @RequestParam int classId, HttpSession session, @RequestParam(required=false) String error){
Optional eazyClassOptional = eazyClassRepository.findById(classId);
EazyClass eazyClass = eazyClassOptional.get();
model.addAttribute("eazyClass", eazyClass);
session.setAttribute("eazyClass", eazyClass);
model.addAttribute("person", new Person());

String errorMessage = null;
if(error != null) {
errorMessage = "Invalid Email entered!!";
model.addAttribute("errorMessage", errorMessage);
}
return "students.html";
}
```

It seemed like the output kept repeating itself until it couldn't anymore and then just crashed.
trouble

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.