0

I have two tables. One has a list of menu items, and the other is just a reference-table to keep track of which items go well with another item. Here's the table layout:

MenuItems            CompMenuItems  
-----------          -------------
MenuItemID <-------  MenuItemID     <---- "Refers to MenuItemID"
Name           ^---  CompMenuItemID <---- "Also refers to MenuItemID"

Since there is a many-to-many relationship between items, the following is entirely possible.

  1. Pepsi goes well with a Hamburger.
  2. Hamburger goes well with a Pepsi.

If I do this, though, when the JSON gets processed, it becomes an infinite loop of including each item in its complementary menu items array.

I'm using Spring MVC with Jersey\Jackson and Hibernate JPA, and I cannot solve this issue. Anyone ever see this particular problem?

therealscifi
  • 362
  • 5
  • 12
  • and JPA has what exactly to do with the infinite loop? The stack trace would tell you what is involved in it, so then you can untag JPA if not part of the problem – Neil Stockton Oct 11 '14 at 06:25
  • JPA inherently forces this issue to be solved higher-up on the stack. Those who use the library likely have dealt with a similar issue before. It is relevant. Thanks. – therealscifi Oct 11 '14 at 21:59

2 Answers2

1

Try annotating CompMenuItem with @JsonIgnore..

http://jackson.codehaus.org/1.0.0/javadoc/org/codehaus/jackson/annotate/JsonIgnore.html

Ignore fields from Java object dynamically while sending as JSON from Spring MVC

Community
  • 1
  • 1
RKodakandla
  • 3,318
  • 13
  • 59
  • 79
0

Have you tried Jackson's object identity @JsonIdentityInfo http://wiki.fasterxml.com/JacksonFeatureObjectIdentity

sethmuss
  • 169
  • 9