Thursday, 31 May 2012

Jersey 2.0 Custom Java Objects

I'm really upset how Jersey 2.0 is handling custom java objects for query parameters.  The Jersey query types can have a constructor that accepts a single String argument, a static method named 'valueOf' or 'fromString' that accepts a single String argument, or a read only List<T>, Set<T> or SortedSet<T>.

It assumes that objects are created from a single parameter.  Most of my parameters are created from multiple parameters combined together.  For example, a location object is usually sent like "?x=0&y=0&z=0".  Why not match these parameters to a type's constructor like Vector3d(int x, int y, int z) assuming the application is compiled in debug or allowing param annotations on constructors and/or getter/setter methods would be a giant step in the right direction.

NIO

Applications that have constant connections/feedback from the user to a server and back normally involved polling, a response ticket for accessing later, or Non-blocking IO of some sort (e.g. Netty).  Today we now have better solutions using Servlet 3.0 with asyncronous request processing and HTML 5's web sockets.

Spring MVC:
http://blog.springsource.org/2012/05/06/spring-mvc-3-2-preview-introducing-servlet-3-async-support/

I'm still investigating how to do this with using Jersey with just Jetty and Tomcat, but it looks like Jersey 2.0 isn't ready yet:
http://jersey.java.net/nonav/documentation/snapshot/async.html
http://jersey.java.net/jersey20.html