eclipse-ee4j / eclipse-ee4j/jersey
Returning a complex Bean type from a resource method is very slow (Jackson provider)
- Dominant language
- Java
- Stars
- 730
- Forks
- 382
- PR merge metrics
- No merged PRs in 30d
Description
Hello,
I integrated a new RESTful endpoint in an existing Tomcat project, using Jersey. I use Jackson as my JSON support provider. For test purposes, I have a pretty simple GET resource method that populates the Bean object and returns it.
My Bean class is pretty complex. I have around 20 bean model classes in total. They are interconnected in a (possibly) circular manner, as shown in the illustration below. Please note that the real scenario and more complex and branched. _(Note: The instances of those classes do not have any circular pointers. If a B2 instance points on a B1 instance, it is not the B1 it is contained in.)_

My problem started by noticing that when I'm returning such a complex structure, the performance is just too slow. Getting an answer back takes "forever" (more than a few minutes). I tried reducing the complexity of the structure and the responses got quicker. My _estimate_ is that as the structure gets more complex, the response time gets longer in an exponential manner.
My initial thought was to put the blame on Jackson. So I tried to serialise the Bean into JSON inside the method and return the String of the JSON. All performance issues were solved.
I then tried to build a MessageBodyWriter and to serialise the Bean there. Also worked fine.
Hence, my current assumption is that maybe the default Writer, or some Mapper, are the cause of this problem. I'm wondering whether it is a bug in Jersey, or in the provider, or am I doing something wrong. Not sure how to proceed.
Would appreciate your help.
Thank you.
Contributor guide
Assessment
This issue has not been assessed yet.