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)
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?