juan_gandhi: (Default)
Juan-Carlos Gandhi ([personal profile] juan_gandhi) wrote2010-01-14 04:48 pm

toJSON on par with toString

I've been thinking lately... say, you are writing a pojo, and it is a good practice to have a good toString(), right? How about toJSON/fromJSON? seems like it would be a good idea to have it everywhere as well, what do you think?

[identity profile] cema.livejournal.com 2010-01-15 02:31 am (UTC)(link)
I think positively.

[identity profile] selfmade.livejournal.com 2010-01-15 03:00 am (UTC)(link)
In C# we have extension methods - special static methods declared separately, but used as regular methods, pretty much like prototype methods in javascript.


public class MyClass {}

// declaration
public static class Ex
{
  public static string toJson<T>(this T obj) { /* serialize to json */ }
}

...

//usage
var myobj = new MyClass();
myobj.toJson();

[identity profile] smalgin.livejournal.com 2010-01-15 03:28 am (UTC)(link)
yes yes yes yes