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

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

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -