0

I have used Jackson that is packaged with RESTEasy provided by JBoss. From the docs,

 annotation @JsonIgnoreProperties can be used to either suppress
serialization of properties (during serialization), or ignore processing of JSON 
properties read (during deserialization).

It is very clear from the definition what its purpose is.

But I was going through this tutorial from JBoss, where the following is mentioned.

Before we proceed, . Retrieving shows from URLs like /rest/venues or /rest/venues/1 almost always results in invalid JSON responses. The root cause is the presence of a bi-directional relationship in the Venue entity. A Venue contains a 1:M relationship with Section s that also links back to a Venue. JSON serialiers like Jackson (the one used in JBoss Enterprise Application Platform) need to be instructed on how to handle such cycles in object graphs, failing which the serializer will traverse between the entities in the cycle, resulting in an infinite loop (and often an OutOfMemoryError or a StackOverflowError). We’ll address this, by instructing Jackson to not serialize the venue field in a Section, through the @JsonIgnoreProperties annotation on the Section entity:

Now I am confused what the actual use of @JsonIgnoreProperties is. Is this annotation absolutely necessary when we have bi-directional relationship. I have seen code that is production, that does not use this annotation for bi-directional relationship and works fine without throwing any error.

please clarify if this annotation is absolutely necessary in bi-directional relationship?

Thanks

brain storm
  • 30,124
  • 69
  • 225
  • 393
  • Are you using the persistence entity model for JSON serialization/deserialization? Or do you have a separate DTO layer? – Rohit Jan 20 '15 at 07:08
  • @Rohit: persistence entity model – brain storm Jan 20 '15 at 07:28
  • Then, as the tutorial mentions you should use the annotation as there is good chance of infinite loop. – Rohit Jan 20 '15 at 08:30
  • You don't have to use it. There are other methods which can help avoiding infinite loops in jackson. http://stackoverflow.com/questions/3325387/infinite-recursion-with-jackson-json-and-hibernate-jpa-issue this one has good examples. – Ghokun Jan 20 '15 at 10:40

0 Answers0