You probably could do that by tampering with the actual Object.class file (compiling your very own version of that, to then replace the .class file in the corresponding JAR file). But I would seriously hope that the JVM notices that, and slaps on your fingers.
Doing it "later", after JVM startup, is fully impossible. The java.lang classes are all loaded by the initial "boot" class loader, which is baked into the JVM, and which you can't change (until you start building your own JVM). So long before any of your code is invoked by the JVM, it has already loaded java.lang.Object, and the implementation from the .class file it found in the file system.
As the comments imply, the real answer here is: you are going down the wrong rabbit hole.
There are probably hundreds, if not thousands of internal APIs or 3rd party libraries that assume that the default toString()
result looks like it does. Of course, relying on that assumption is a bad idea, but nonetheless, your change could break such code.
Beyond that, the real answer is: when you don't like the default behavior, change it for those classes that matter to you.
Update 1, one other (theoretical) approach: it might be possible to hook into the class loader, so that when specific "user classes" get loaded, that process is intercepted, and a generated toString() method is added (probably what the OP tried with javaasist). But the OP wants to do this in a tomcat context, and tomcat has its own complex hierarchy of class loaders. No realistic chance for this option either! And even if you would have full control over class loaders, we are talking "black magic voodoo" style hacking here. Things you do for an education project, but not for something that has to function robustly and reliably in the real world.
Update 2, regarding the updated requirements. The OP basically wants to change specific behavior of classes without re-compiling them. But given the other requirements, this is simply not possible here. All options to enable such "dynamics" in Java are not suited for a real world production environment.
Thus the answer simply stays put: what the OP asks for might be theoretically possible, but for all practical purposes, it is not feasible.