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

Popular posts from this blog

php - cannot display multiple markers in google maps v3 from traceroute result -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -