lundi 24 octobre 2022

Overriding toString() of generated code in Java 8

I am required to use a generated Java class to connect with a third-party application, and we frequently have to regenerate that Java class with new field names. The generated Java class does not have a toString() method for easy viewing of the fields, and the toString() method it inherits from its base class (which we cannot change) is useless for viewing fields in the generated Java class. I am not permitted to change the generated Java class in any way except to regenerate it when necessary, and I do not have access to the class code generator itself. I also cannot use any other Java version than 8. We have many generated Java classes like this.

Is there a way to extend the useless toString() method used by the generated code so we can see the fields in the generated code classes? I'm not sure that wrapping with a method like "stringify" would work because lots of code relies on the generated code classes functioning as they do right now; perhaps toString() can be extended dynamically with reflection?

Can anyone give me any ideas for how I might be able to make this work?

Thanks!





Aucun commentaire:

Enregistrer un commentaire