While on the lookout for a JSON serializer that would allow me to include or exclude parts on a per-serialization basis instead of just per-class basis (which is what Json.NET gives me), I ran into FlexJSON. Unfortunately, it's for Java, and I'm working in C#. What's a programmer to do?
Well duh, port it, of course! What better way to learn the ins and outs of the library? :)
I hacked on the sources for about three hours today. I started out by changing all the file extensions from .java to .cs, then opening the things in VS.Net and pretty much mechanically changing the incompatible bits, accessors to properties and whatnot. Surprisingly little effort there -- the Java and .NET reflection classes are very much alike.
I haven't had the time to understand all of the code properly yet, for example I still need to figure out what the deal is with the chained set and iterator thing. I suspect it has to do with avoiding reference loops in object graphs.
I'm not sure whether or not this will ever be finished, but I'm going to give it some more time tomorrow. I'm hoping to get it to a point where I can start running the test cases and see what breaks.
If I should be so lucky as to actually get this thing done, I think I'll try to wrangle a permission to publish the port. What I'd really like to see, though, is this feature in Json.NET since that's what I'm currently using and from what I gather, it also ships with MonoRail these days. Tomorrow I'll probably have a better idea of what it would take to add the feature. No promises though.
Edit: Json.NET does support the feature I'm looking for after a fashion -- but I gather that I'd have to walk the object graph myself. So basically grafting on something similar to the FlexJSON path expressions might just do the trick.