I have an object MyMsg, which one of its properties is a large binary String.
class MyMsg {
public String moreSmallStuff;
//May contain a binary String
public String bin;
}
I am using RabbitMQ to push a msg to a queue so other processes can do their stuff against that new MyMsg object. But the sent message should be in json.
I am having troubles serializing that object with java gson if it contains a large binary string (i.e. +30 MB).
gson.toJson(object);
It fires an OutOfMemoryError exception. So, in order to fix it I have added: -Xmx1024M to the java VM, so it has been fixed in part.
However I really do not like it because it can still crash due to possible bigger files and it seems to me highly inefficient. Is there a better way to parse the object which contains a binary String like that with better performance and memory-use-safer? The binary is just about that size, I cannot believe it requires a 1 GB of RAM to process it.
Thank you very much.