Genson - Error on Serialization

130 views
Skip to first unread message

Usc La

unread,
Mar 27, 2015, 12:53:44 PM3/27/15
to gen...@googlegroups.com
I am getting the following error when I serialize from Map (HashMap) to String.

Failed to serialize object of type class java.util.HashMap.

    Map<String, Obj> res = getResults();

    Genson genson = new Genson();

    String maptoJSON = genson.serialize(res);

It works fine locally on my system (MAC) but does not work on the Stage box (Unix).

Obj is a class which has a few fields in it.

Ap

Eugen Cepoi

unread,
Mar 27, 2015, 1:00:01 PM3/27/15
to gen...@googlegroups.com
Can you please provide the content of the map, the full stacktrace and the version of Genson you use?
There should be no problem with serializing a map, I think it is related to the content inside the map.

Thanks,
Eugen

--
You received this message because you are subscribed to the Google Groups "Genson user group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to genson+un...@googlegroups.com.
To post to this group, send email to gen...@googlegroups.com.
Visit this group at http://groups.google.com/group/genson.
To view this discussion on the web visit https://groups.google.com/d/msgid/genson/4337b495-3996-4169-9fdc-51f195acfb49%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Usc La

unread,
Mar 27, 2015, 1:18:34 PM3/27/15
to gen...@googlegroups.com

public class Obj {

ArrayList< ObjB > returns;

ArrayList< ObjB > trailingReturns;

}

public class ObjB implements Serializable {

Long returnDate;

Double netReturn;

Double aum;

Usc La

unread,
Mar 27, 2015, 1:22:25 PM3/27/15
to gen...@googlegroups.com
Genson 1.2

Eugen Cepoi

unread,
Mar 27, 2015, 1:33:15 PM3/27/15
to gen...@googlegroups.com
From the information you provided nothing looks wrong and should work.
I can not help without more infos. What are the differences between your local environment and the one you deploy (linux/mac/windows should not matter as Java provides the abstraction), seeing the full stacktrace would help even more.

The best being to provide a code that I can run to reproduce the problem.


Usc La

unread,
Mar 30, 2015, 7:36:53 PM3/30/15
to gen...@googlegroups.com
So looks like, there is a SIZE issue.

If I cross a certain size, the map gives serialization error.

Any solution for this ?

Ap

Amay Patil

unread,
Mar 30, 2015, 9:16:42 PM3/30/15
to gen...@googlegroups.com
Found the Solution. Increasing the Heap Size fixed the problem.

Ap
--
You received this message because you are subscribed to a topic in the Google Groups "Genson user group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/genson/oErYhTAPLRc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to genson+un...@googlegroups.com.

To post to this group, send email to gen...@googlegroups.com.
Visit this group at http://groups.google.com/group/genson.

Eugen Cepoi

unread,
Mar 31, 2015, 5:19:21 AM3/31/15
to gen...@googlegroups.com
Increasing the heap size delays the problem but doesn't really fix it.
If you serialize to a string then for sure you might have memory issues for large objects as you would have the object in memory + its serialized form at the same time. You have alternate methods genson.serialize(object, Writer/OutputStream) that you could use.

About the exception "Failed to serialize object of type class java.util.HashMap." it is the top level one, but you should see in your logs/output a sequence of exceptions that are more detailed. The last one should have the valuable information.



--
You received this message because you are subscribed to the Google Groups "Genson user group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to genson+un...@googlegroups.com.

To post to this group, send email to gen...@googlegroups.com.
Visit this group at http://groups.google.com/group/genson.
Reply all
Reply to author
Forward
0 new messages