Uncategorized

JSon and GSON

There is a nice library that makes creating and reading JSON object fun: Google GSon. I use it in every class of mine to implement a toString() method. You can even use to to implement the clone() method (if you don’t care about performance):

class VariableDefinition {
	public String toString()
	{
		Gson g = new Gson()
		g.toJson(this)
	}

	public VariableDefinition clone()
	{
		Gson g = new Gson()
		g.fromJson(g.toJson(this), VariableDefinition.class)
	}
}

The reason why I use to add a toString() method to every class is that the eclipse debugger uses this method to display complex objects nicely:

Leave a Reply

Your email address will not be published.