java - OK to use JSON output as default for toString()? -
@override public string tostring() { return new gson().tojson(this); }
am breaking practice, "joshua"-pattern thing, general design pattern or other convention doing default behavior model objects?
tostring()
anyhow used in debugging in paradigm (android) using. that's reason why seeing object in json since orm/json persistence happening through http->php/python->mysql , local sqlite.
there's no harm in doing way. suggest create static variable gson
instance , enable pretty printing:
static gson gson = new gsonbuilder().setprettyprinting().create();
this way output tostring
method formatted.
Comments
Post a Comment