What's New
Saturday, March 6th, 2010

I love Lightwire for dependency injection, it’s lightweight, it’s not XML based, and allows for mixins which saves me from having to constantly add constructor properties or setters. However, I was recently confronted with a problem. When using Lightwire for transient beans, I often found myself wanting to inject dependencies, but also pass in some properties/dependencies at runtime (for example, some data somebody entered in a form). Now, an obvious way to do this would be to define the bean without that dependency, create a setter for it, and then add whatever you need to the bean using that. Somehow, it felt like kind of a roundabout way of doing it, so I figured I’d look for a way to be able to do it at the time of bean invocation. In terms of code, here’s what I was looking for:

myBean = application.lightwire.getBean("myBean", form.runTimeData, form.moreData);

INSTEAD OF

myBean = application.lightwire.getBean("myBean");
myBean.setRuntimeData(form.runTimeData);
myBean.setMoreData(form.moreData);

Note that you could also do the above with one setter that would set all the runtime data you want at once. Still, it’s an extra call, and that just bothers me to no end! So after some modifications to the Lightwire code I was almost able to do what I wanted, with a small caveat. I wasn’t able to use numbered arguments, had to settle for named arguments for now (though I’m still working on it). So right now I’m able to do this:

myBean = application.lightwire.getBean(
	objectName="myBean",
	runTimeData=form.runTimeData,
	moreData=form.moreData
);

I’m not 100% happy with it because I’d like to get it working with numbered argument and avoid all that typing, but the arguments/argumentCollection object is a weird one and I haven’t been able to swing that yet. Hoping I’ll come up with some sort of solution eventually (if anybody has some insights in the Java internals of argumentCollection and how to manipulate that, I’m all ears). But for now this works for me.

I’m interested in knowing if anybody else would find this feature useful, or if for any reason this would be bad practice and maybe I’m going about things all wrong. Again, I know it’s kind of a small nitpicky thing, but when you’re coding all day, small details make a big difference!

Wednesday, February 20th, 2008

It’s been way too long I’ve owed an update of CFJSON. There were a few nagging bugs that needed to be addressed and I did my best to fix them. Another notable improvement was related to performance. Ray Camden pointed out that string concatenation wasn’t using the Java StringBuffer object. Doug Boude provided me with some code and I plugged it in, so encoding should be considerably faster when dealing with a lot of data.

Apologies to those who submitted other fixes/suggestions that are not addressed by this release. Either I found problems with the submission or including it would have further delayed a long-overdue release, so I figured I’d keep it for the next one. Either way, thanks for all the comments and code contributed.

For more details on the changes and to download the latest version, go to the CFJSON site.

Saturday, May 12th, 2007

It’s been a while I’ve updated CFJSON, I just finished looking over some suggestions I’d received by email and took a little time to implement and test them. One fix could be considered critical depending on your needs. Ray Camden pointed out that Yahoo’s JSON feeds escaped the forward-slash character, so a url was coming up as http:\/\/someURL.com . This was not being decoded correctly by CFJSON, which I fixed for this release. For consistency, I also modified the encode function to escape the forward-slash.

The next two changes are some optional features that might make your life easier. The first was a suggestion by Carl Anderson for the handling of numeric fields. He was having problems because he had some project codes like “5.10000″ which javascript would convert to 5.1. He recommended that numbers be converted to strings by default in JSON. Because So he added a stringNumbers argument to the encode() function, when set to true it will encode numbers as strings. Because I don’t like to tamper with data unless necessary, I preferred to set the default to false.

Next up was the handling of dates. Thomas Jaworski pointed out that dates in an ODBC format like {ts ’2007-04-15 16:03:25′} would be troublesome to parse, so he provided some code for the encode() function to format dates in a way that was friendly to javascript’s new Date() constructor. Again, because I don’t like to tamper with data I preferred to implement this as an option that is false by default. The encode() function takes an optional formatDates boolean argument which will format dates as follows: May 12, 2007 3:00:45 PM .

Hopefully these features will come in handy. As always, your feedback is welcome, keep the requests/suggestions coming!