Porting from Java to C#

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.

A new beginning

It’s been a while since I abandoned my previous blog. I did it for a couple of reasons. First, I’d really like to focus more on software development and my experiences in it than the rest of my life, and second, keeping WordPress up to date was really getting on my nerves. I do like to express myself in writing, though, so I thought I’d give it another shot. I have a couple of topics on my mind already. 🙂

Till later.

1 9 10 11