Jackson JSON and Dynamic JSON creation

FasterXML Jackson is a great tool for converting objects to/from POJOs.

Its a great tool when we know the structure of JSON beforehand. But what if we don’t know that? In that case we can use a Map<String, Object> to store the unknown objects. Below two links provide useful info:

http://stackoverflow.com/questions/18043587/why-im-not-able-to-unwrapp-and-serialize-java-map-using-jackson-java-library

http://www.cowtowncoder.com/blog/archives/2011/07/entry_458.html

Happy Coding :)

Creating collection of Spring Beans

Some times there might arise situations where you want to create a number of Spring Beans, but you don’t know how many beans are there at coding time.

Usually, you create a Spring bean as follows:

But what if you want to create 50 such beans which differ only in the argument supplied to the constructor? Or a similar case arise where the number of beans to be created cannot be determined at coding time?
In such cases, we can create the bean definitions and add the beans to Spring container at runtime using BeanFactoryPostProcessor.

Implement BeanFactoryPostProcessor in either a @Configuration file or a @Component bean(make sure this bean gets scanned and created).

If there are more than one constructor arguments, the call can be chained as follows:

All this works fine when you have to create a bean using constructor. But :( I haven’t figured out how to do this when we use a chain of factory methods to create a bean as follows:

Happy Coding! :)

Skandagiri

About two months back, me and a friend of mine went for trekking at Skandagiri Hills. Its about 75km from Bangalore near to Nandi Hills. 

 

 

We started on my Yamaha Fz at about 2:30AM and reached there by 4.30AM. The place has got a few locals who are waiting there to get hold of your money in the form of parking and acting as guide! We parked (gave the guy Rs20/30 just to make sure he don’t destroy my bike) and dismissed the idea of having a guide. The trek started and we reached the top by 5.15 in the morning. The view was awesome!
Here is a map of the area and route to be taken. It’ll save you the cost of having a guide and give you a sense of adventure as you are finding way through pitch dark (if there is no moonlight ;)). Remember to take a good torchlight and a jacket. It’ll be very cold at the top. Its an easy trek. Once you find the muddy lane you can easily reach the top – you don’t require any guide! There is a small catch though – there is a route which you shouldn’t take – its marked in red colour. This red route is considerably wider and it reaches a dead-end! But what’s the fun if there is no thrill in finding the right way!

skandagiri_map

 We started back by 10 in the morning. On the way back we stopped at a small Fort near Nandi hills – Fort Devanahalli. Took some pictures and then headed back to Bengaluru!

Hearing it from the granpa!

I was searching for good JavaScript resources and then stumbled onto this guy – Douglas Crockford. Douglas Crockford is Yahoo!’s JavaScript architect. He is also the creator of JSON and the author of the book which I am reading now – Javascript: the good parts. He is one of the most authoritative person to talk about JavaScript.

I found his talks on JavaScript and just finished watching the first part.

Its a video which I wish I had seen when I was in my Engineering class! The first part talks nothing about JavaScript. Its about the history of computing and programming languages. His talk, unlike our Computer Science teachers, is very inspiring – and the reason is, he has EXPERIENCED it (atleast most of it) and not just read about it in some book. The way he speaks about punch card readers, early computers etc. remind you of the way old people tell you the stories of their childhood – with passion and love.

Now I should watch the remaining of the series.

Happy Coding and Keep smiling :)

Musings of a Windows-using Linux fan!

And now, the previous blog post made me thinking… Why didn’t I learn .NET, C#, DirectX or other Microsoft technologies?
Maybe, because I am a fan of opensource platforms (excuse, I know there is Mono), languages and tools.
And maybe, there is a little Leftist hidden in me. (I would like to call myself opportunistic Leftist though :), and by the way I believe most of the Keralites have a soft corner for Communist beliefs – that’s why Kerala is one of the few states where Communists are still strong). And the words opensource and free software bring the thoughts of Freedom, independence and revolution to the mind.
Using Microsoft technologies, means tied to Microsoft platform and tools. I guess the leftist in me doesn’t want to get tied up.

PS: I switched back to using Windows a couple of years ago though. Was a hardcore Linux fan before. If I hadn’t I would have turned into a mad FOSS fanatic! Phew.. that didn’t happen, and am glad it didn’t!

First half of 2014

The past 6 months had been very fruitful for me. I have added many stuffs to my skill set in this small span of time. Here are some of it:

  • The new Java kid – Java 8
  • Spring Security
  • Creating zero-xml Spring projects using Spring javaconfig and Spring Boot
  • Spring AOP
  • Git(had used it before, but had been using it almost daily for past 6 months)
  • Redis
  • Spring Data Redis
  • Spring Data JPA
  • REST(using Spring’s REST as well as JAX-RS spec)
  • Security – PKI, Encryption-Decryption, Certificates, Auth mechanisms (like BASIC and Digest) etc., How to use tools like Fiddler
  • C# – Read-only knowledge :) I don’t know to write a single line of code in C#, but I can understand a fairly large C# codebase given some time. I think that’s fair amount of improvement for a guy who haven’t looked into .NET code before.

Hmm.. that’s a pretty impressive list ;)

Happy Coding! :)