Rest and JSON in JQuery - Twitter Gadget

I am sure you guys must have seem lot of gadget floating around the web for twitter, yahoo, google and what not.

Did you ever thought that writing a small gadget is such a small and minutes job with jquery and the apis exposed by these social networking sites like facebook and twitter. I just tried hands on one of the those and it was quick to get this twitter gadget ready to be shared.

Simple JSON script like the one below can do the whole trick for you.


$(document).ready(function(){
var tweeturl = "http://twitter.com/status/user_timeline/
rahuljuneja.json?count=5&callback=?";
$.getJSON(tweeturl, function(data){
$.each(data, function(i, item) {
$('

').addClass(i%2 ? 'even' : 'odd')
.html(item.text)
.prependTo('#tweet');
});
});
});

Interface handling in REST and JAXB

It is a very common scenario when you are writing a class implementing and interface and your parameters to the classes are interfaces.

eg:

 
public interface Person {}

@XmlRootElement
public class Employee implements Person {}

@Path("/persons")
public class MyEmployeeResources {
@PUT
@Consumes("application/xml")
public void putEmployee(Person person) {...}
}

In the above example you will get an error with Jersey or RESTEasy as they both don't know the implementation of Person are JAXB class, hence they don;t have the context of JAXB.

Really cool alternative to this was to use @XMLSeeAlso annotation. something like below

 
@XmlSeeAlso(Employee.class)
public interface Person {}

This way JAXB creates the JAXBContext of Person, because it knows that it can be unmarshal with Employee or Student class.

Similarly @XMLSeeAlso can be used with JAX-WS.