Monday, October 15, 2007

User defined types with JsonMarshaller

I came across the JsonMarshaller project while searching for a Java library for unmarshalling JSON. This is a nifty little framework and uses Java 5 annotations for marshalling and unmarshalling JSON.

JsonMarshaller provides simple annotations @Entity and @Value for marking up your classes for marshalling and unmarshalling. However, I wanted something more than what the base framework provides - the ability to convert dates back and forth. The framework supports a so called type option to specify a user defined type for a value. This is a cool idea for extending the basic types supported out of the box. The (simplified) code for my DateType class that solved my problem is below:



public class DateType implements Type {

@Override
public Class getReturnedClass() {
return Date.class;
}

@Override
public Object marshall(Date entity) {
SimpleDateFormat format = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z");
return format.format(entity);
}

@Override
public Date unmarshall(Object object) {
String date = (String) object;
Date d = null;
try {
d = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z").parse(date);
} catch (ParseException e) {
e.printStackTrace();
}
return d;
}
}




This simple class can read a String representing a date in most commonly used formats and return a java.util.Date. It can also read a java.util.Date and return a String representing that date.

Create your family tree with Geni

I came across this really cool website that let's you create your family tree. It's got a cool interface that let's you and family members you invite add new members to your tree. Really cool - loved it.

Claiming my blog in Technorati

Technorati Profile

Thursday, October 11, 2007

TightVNC client getting killed after Windows locked?

If you are wondering, like I was, why your TightVNC viewer dies after your Windows workstation running the server is locked, here's the answer.

Briefly, from the link above:
"This is a standard behavior. You have to run TightVNC Server as a service if you want to avoid this problem."
So there.

Pidgin + Pidgin plugin pack on Ubuntu

Pidgin is an open source multi-protocol chat client. Since I use AIM at work and most of my friends listen in on GTalk, I decided to install Pidgin. A quick Google search unearthed this link. But hey, what's the point of being on Linux and not performing the configure-make-make-install drill? Besides, I wanted the Pidgin Plugin Pack as well (which btw can also be installed by following the instructions here without building the sources). This pack has an extremely useful plugin - Mystatusbox - that allows you to selectively set the status of each of your IM accounts. So here's how I got around to getting both Pidgin and Pidgin plugin pack on my box:
  1. download pidgin 2.2.1 source from sourceforge
  2. downloaded various dependent sources (libxml-dev, libgtk-dev) and installed these
  3. ./configure && make && sudo make install
  4. downloaded the pidgin plugin pack from here
  5. ./configure && make && sudo make install
I threw in a desktop launcher for good measure, and I was good to go.