Friday, June 27, 2014

Dealing with IBAN / BIC in Java? ...check iban4j #iban #java #iban4j

This post is mostly targeted to Java developers working on the financial sector, especially with systems that need to do payments and specifically using the IBAN/BIC standard.

So today I was browsing through some 'legacy' code, that was performing some sort of validations on String representations of IBAN accounts. I wrote a simple JUnit  test, in order to check if the validations performed from this very very old JAVA 1.4 (or older) style of code, were eventually correct.

 To my surprise I realized that a few bugs or missing cases were floating around. I started digging further, missing empty/null string or formatting exceptions, specific formatting decisions based on specific countries and many other issues led to starting asking myself how I can efficiently correct the code and eventually 'secure' this part of the system that was relying on such error prone validations. 

After some more digging around, I found that there are actually 2 good candidates, for my case
I reviewed the API and functionality offered by both. To be fair IBANCheckDigit from Apache is some sort of utility class, while iban4j is a complete mini library that covers, creating, formating and checking of IBAN and BIC literals.

I re-used my unit test, replacing the legacy code with calls to ibanj, after including the dependency on my pom. All test passed, all validations and exceptions caught. I had a clear winner.

Many thanks to the developer, for sharing such a handy library. The API is clean and simple and the functionality conforms to the standards. At least it passed my legacy compatibility tests.

So in case you find yourself in a similar situation...give iban4j a go!


1 comment: