When trying to convert a JPA object that has a bi-directional association into JSON, I keep getting
org.codehaus.jackson.map.JsonMappingException: Infinite
Be sure you use com.fasterxml.jackson everywhere. I spent much time to find it out.
2.9.2
com.fasterxml.jackson.core
jackson-annotations
${fasterxml.jackson.version}
com.fasterxml.jackson.core
jackson-databind
${fasterxml.jackson.version}
Then use @JsonManagedReference
and @JsonBackReference
.
Finally, you can serialize your model to JSON:
import com.fasterxml.jackson.databind.ObjectMapper;
ObjectMapper mapper = new ObjectMapper();
String json = mapper.writeValueAsString(model);