@SuppressWarnings("unchecked")
    public static final <T> TypeHandler<T> getTypeHandler(Class<T> cls) {
        TypeHandler<T> res = (TypeHandler<T>) typehandlers.get(cls);
        if (res == null) {
            throw new EncodingException("No handler registered for class: " + cls.toString());
        }
        return res;
    }