Search code examples
javacode-generationpojojooq

I want to add annotations to jOOQ generated classes


I would like to add some annotations to generated pojo and dao classes. I know that I can override

JavaGenerator.printClassAnnotations(JavaWriter out, SchemaDefinition schema)

but problem is that this method is called for every generated file. I don't know how to limit my changes just for pojo or dao since I am not getting mode passed in :( Is there some other way? Thx.


Solution

  • Unfortunately, it is currently not easily possible to customise the generation output on this level.

    A major rewrite of the code generator is planned for jOOQ 4.0, and custom annotations will definitely be part of it. Until then, I can think of these workarounds:

    • Implement some text-based post processing that patches annotations into the generated files at the appropriate positions
    • Override the JavaGenerator, replacing the relevant methods with a patched version
    • Patch the JavaGenerator with your own custom logic

    The last two workarounds will be the most powerful, although (obviously) at the risk of breaking at every minor release.