0

I have a very complex object which I so far I used to serialize it to xml via @XmlRootElement and worked perfectly well. Now I am writing REST and I need to serialize it to json. What happens is it throws StackOverflowError exception. What I wrote so far is that the reason could be bi-directional mapping, but this is not the case with me I think. What could be the reason and how can I track if I miss bi-directional mapping, the object is really complex and supported from many people for very long time, is there a simple way I can track this that I can't think of? Thanks!

EDIT Here is stack trace:

StackOverflowError
    java.util.regex.Pattern.sequence(Pattern.java:1902)
    java.util.regex.Pattern.expr(Pattern.java:1769)
    java.util.regex.Pattern.compile(Pattern.java:1477)
    java.util.regex.Pattern.<init>(Pattern.java:1150)
    java.util.regex.Pattern.compile(Pattern.java:840)
    net.sf.json.regexp.JdkRegexpMatcher.<init>(JdkRegexpMatcher.java:38)
    net.sf.json.regexp.JdkRegexpMatcher.<init>(JdkRegexpMatcher.java:31)
    net.sf.json.regexp.RegexpUtils.getMatcher(RegexpUtils.java:39)
    net.sf.json.util.JSONTokener.matches(JSONTokener.java:113)
    net.sf.json.JSONObject._fromJSONTokener(JSONObject.java:962)
    net.sf.json.JSONObject.fromObject(JSONObject.java:156)
    net.sf.json.util.JSONTokener.nextValue(JSONTokener.java:350)
    net.sf.json.JSONObject._fromJSONTokener(JSONObject.java:1006)
    net.sf.json.JSONObject.fromObject(JSONObject.java:156)
    net.sf.json.util.JSONTokener.nextValue(JSONTokener.java:350)
    net.sf.json.JSONObject._fromJSONTokener(JSONObject.java:1006)
    net.sf.json.JSONObject.fromObject(JSONObject.java:156)
    net.sf.json.util.JSONTokener.nextValue(JSONTokener.java:350)
    net.sf.json.JSONObject._fromJSONTokener(JSONObject.java:1006)
    net.sf.json.JSONObject.fromObject(JSONObject.java:156)
    net.sf.json.util.JSONTokener.nextValue(JSONTokener.java:350)
    net.sf.json.JSONObject._fromJSONTokener(JSONObject.java:1006)
    net.sf.json.JSONObject.fromObject(JSONObject.java:156)
    net.sf.json.util.JSONTokener.nextValue(JSONTokener.java:350)
    net.sf.json.JSONObject._fromJSONTokener(JSONObject.java:1006)
    net.sf.json.JSONObject.fromObject(JSONObject.java:156)
    net.sf.json.util.JSONTokener.nextValue(JSONTokener.java:350)
    net.sf.json.JSONObject._fromJSONTokener(JSONObject.java:1006)
    net.sf.json.JSONObject.fromObject(JSONObject.java:156)
    net.sf.json.util.JSONTokener.nextValue(JSONTokener.java:350)
    net.sf.json.JSONObject._fromJSONTokener(JSONObject.java:1006)
    net.sf.json.JSONObject.fromObject(JSONObject.java:156)
    net.sf.json.util.JSONTokener.nextValue(JSONTokener.java:350)
    net.sf.json.JSONObject._fromJSONTokener(JSONObject.java:1006)
    net.sf.json.JSONObject.fromObject(JSONObject.java:156)
    net.sf.json.util.JSONTokener.nextValue(JSONTokener.java:350)
    net.sf.json.JSONObject._fromJSONTokener(JSONObject.java:1006)
    net.sf.json.JSONObject.fromObject(JSONObject.java:156)
    net.sf.json.util.JSONTokener.nextValue(JSONTokener.java:350)
    net.sf.json.JSONObject._fromJSONTokener(JSONObject.java:1006
elm
  • 20,117
  • 14
  • 67
  • 113
user2266685
  • 191
  • 1
  • 2
  • 8
  • Try catching the SOE in a debugger and looking at the stack trace. You should be able to track that back to what is causing it. – mikea Aug 26 '14 at 16:28
  • If you use intellij/eclipse, there are tools to help detect cyclical dependencies in your object model. Or use third party tools out there that you can search for on Google. Worst case, you can traverse your object hierarchy from your base object and track it yourself to see if there exists a cycle – coffeeaddict Aug 26 '14 at 18:03
  • Show us the first 2 dozen or so of the exception stack trace entries. – Hot Licks Aug 26 '14 at 18:53

1 Answers1

0

You better post your object and the code that you use to deserialize it. Also, you can try doing it with a different library:

Jackson( the more-more-or-less standard lib for that): http://www.mkyong.com/java/how-to-convert-java-object-to-from-json-jackson/

GSON: JSON GSON.fromJson Java Objects

Community
  • 1
  • 1
Nikola Yovchev
  • 9,498
  • 4
  • 46
  • 72