Question

I am working on developing a JAX-RS webservice using RestEasy 2.2.2 to be deployed on Tomcat 7. The webservice returns JSON (via Jackson) to the clients. I got it working so far but I am not sure how to build the dynamic links that needs to be sent to the clients.

The following comes to my mind:

1- Make a deep copy of the root object (that itself contains other objects, three levels total), modify the String properties that represent the links, and return this new object.

Concern: Performance, getting the deep copy implementation correct

2- Modify the object per request and return it

Concern: Concurrency issues (I am not even sure if this is even possible)

3- Build a new root object, iterating over the "main object" and modify/add as needed

Concern: Similar to (1). Basically this is implementing a copy constructor vs. cloning() the object.

The only example I could find (scroll down to the "JAX-RS resource class" section) seems to implement option 3. However, if I am not mistaken, it also behaves like option 2 (it modifies the object and adds to the collection) and I am not sure how the concurrency issues are handled.

Thank you in advance for any guidance, help and opinions.

Was it helpful?

Solution

In case anyone reads this question in the future: I went with the "serialize-deserialize in memory" route to get a fresh copy and built the links dynamically on this fresh copy. I already have JSON readers and writers available so the solution was available with very little work (single line for the actual call, to be exact). For the purposes of the project, it seems to work fine (in terms of performance).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top