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
3
  • 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. Commented Aug 26, 2014 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 Commented Aug 26, 2014 at 18:03
  • Show us the first 2 dozen or so of the exception stack trace entries. Commented Aug 26, 2014 at 18:53

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.