-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Converting a large java object to String containing json format #1176
Comments
There are overloads of |
I did use this method in the below mentioned code,but it seems to use more memory compared to (gson.toJson(this))
|
That still buffers the entire payload in memory as bytes. The stream should
be hooked up to your destination such as a file or socket.
…On Tue, Oct 24, 2017, 12:01 PM Ashok Borra ***@***.***> wrote:
I did use this method in the below mentioned code,but it seems to use more
memory compared to (gson.toJson(this))
GsonBuilder gsonBuilder = new GsonBuilder();
gson = gsonBuilder.serializeNulls().create();
//return gson.toJson(this);
// OutputStream out = new ByteArrayOutputStream();
ByteArrayOutputStream outt = new ByteArrayOutputStream();
JsonWriter writer = new JsonWriter(new OutputStreamWriter(outt, "UTF-8"));
writer.beginArray();
gson.toJson(this, this.getClass(), writer);
writer.endArray();
writer.close();
—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
<#1176 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAEEEQS5H8nqjvmcOV36p3IiteTNT6Llks5svcN0gaJpZM4QCsMU>
.
|
In the end state we need it as a String,what approach do you suggest ? |
There's no magic fix. You either need a larger heap or a smaller object.
…On Tue, Oct 24, 2017, 1:05 PM Ashok Borra ***@***.***> wrote:
In the end state we need it as a String,what approach do you suggest ?
—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
<#1176 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAEEEWhvmPTTtvQWIUu8O4dWVgcUGRZZks5svdKJgaJpZM4QCsMU>
.
|
this refers to a large java object,I get out of memory exception while converting,also our heap size is 1 GB.Any workaround for this ?
The text was updated successfully, but these errors were encountered: