This seems like it'd be a good place to introduce a controller servlet that shuffles the request off to an appropriate handler. The handler returns the object, the servlet knows what return type the request needs, and converts the object appropriately. If I was at that stage, though, I'd already be looking into any number of existing frameworks that can handle some of that for me.
Won't you please? Please won't you be my neighbor? - Fred Rogers. Tiny ad: