best way to add a new line to every gson serialization?

1,547 views
Skip to first unread message

Aleem Mawani

unread,
Sep 14, 2012, 2:05:20 PM9/14/12
to googl...@googlegroups.com
Is there a relatively standard/easy way to add a new line to the end of every serialization by a Gson? I.e. something similar to setPrettyPrinting that just adds an extra line at the end?

Brandon Mintern

unread,
Sep 14, 2012, 3:31:33 PM9/14/12
to googl...@googlegroups.com
Personally, we have our own class (called Json) that implements a
bunch of convenient static methods that delegate to a single Gson
instance internally. This allows us to register all of our GsonBuilder
customizations in a single place. Doing something like this would
allow you to define a simple method:

public String prettyPrint(Object o) {
return gsonInstance.toJson(o) + '\n';
> --
> You received this message because you are subscribed to the Google Groups
> "google-gson" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/google-gson/-/OMvZXqYMVw8J.
> To post to this group, send email to googl...@googlegroups.com.
> To unsubscribe from this group, send email to
> google-gson...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/google-gson?hl=en.
Reply all
Reply to author
Forward
0 new messages