Am 04.08.2015 08:21, schrieb Esteban Gínez:
Hi all.
Lately I have been using JsonOutput to handle my json serialization and
I find that having JsonOutput.toJson overloaded is pretty nifty.
However when trying to pretty print an object the calls look like this
JsonOutput.prettyPrint(JsonOutput.toJson(object))
And that's pretty awkward in my opinion.
I'd like to propose a change the following change
def prettyPrint = true
JsonOutput.toJson(object, prettyPrint)
Used as category your original code reduces to:
object.toJson().prettyPrint()
and I think that is ok.
We would have an overloaded methods of the .toJson call one with a
boolean prettyPrint and the legacy without the boolean parameter(for
backwards compatibility), like so:
/**
* @return a JSON object representation for a map
*/
public static String toJson(Map m) {
if (m == null) {
return NULL_VALUE;
}
CharBuf buffer = CharBuf.create(255);
writeMap(m, buffer);
return buffer.toString();
}
//New overloaded method(s)
public static String toJson(Map m, boolean prettyPrint) {
String buffer = toJson(m);
if(buffer == null){
return NULL_VALUE;
}
return prettyPrint ? JsonOutput.prettyPrint(buffer.toString())
: buffer.toString();
}
Comments? Ideas?
what about the 12+ other variants? You want to add this to each of those?
bye blackdrag
--
Jochen "blackdrag" Theodorou
blog: http://blackdragsview.blogspot.com/