jooqjooq-codegen

How to map json columns to String fields when generating Java objects


When Jooq generates Java objects, the json columns are mapped to org.jooq.JSON fields by default.

`keywords` json DEFAULT NULL COMMENT 'keywords',
private JSON keywords;

I want to map json columns to java.lang.String fields. How should I set up the xml configuration file?

Thanks.

The database I am using is MYSQL8.


Solution

  • You can use data type rewriting in the code generator, pretending those are VARCHAR columns. E.g.

    <forcedType>
      <name>VARCHAR</name>
      <includeExpression>(?i:keywords)</includeExpression>
    </forcedType>
    

    Or even:

    <forcedType>
      <name>VARCHAR</name>
      <includeTypes>(?i:json)</includeTypes>
    </forcedType>
    

    See the manual for all configuration options