Jackson converters
Applies to ✅ Open Source Edition ✅ Express Edition ✅ Professional Edition ✅ Enterprise Edition
In case your database column is of type org.jooq.JSON
or org.jooq.JSONB
, you may want to attach a custom data type binding that is backed by the popular Jackson library. It is easy to achieve manually using a hand-written Converter, but you can also use the following convenience configuration:
<configuration> <generator> <database> <forcedTypes> <forcedType> <!-- Specify the Java type of your custom type. This corresponds to the Converter's <U> type. --> <userType>com.example.MyType</userType> <!-- Apply the built in converter of type - org.jooq.jackson.extensions.converters.JSONtoJacksonConverter or - org.jooq.jackson.extensions.converters.JSONBtoJacksonConverter. --> <jsonConverter>true</jsonConverter> <!-- A Java regex matching fully-qualified columns, attributes, parameters. Use the pipe to separate several expressions. --> <includeExpression>.*\.JSON_COLUMN</includeExpression> </forcedType> </forcedTypes> </database> </generator> </configuration>
See the configuration XSD, standalone code generation, and maven code generation for more details.
new org.jooq.meta.jaxb.Configuration() .withGenerator(new Generator() .withDatabase(new Database() .withForcedTypes( new ForcedType() // Specify the Java type of your custom type. This corresponds to the Converter's <U> type. .withUserType("com.example.MyType") // Apply the built in converter of type // // - org.jooq.jackson.extensions.converters.JSONtoJacksonConverter or // - org.jooq.jackson.extensions.converters.JSONBtoJacksonConverter. .withJsonConverter(true) // A Java regex matching fully-qualified columns, attributes, parameters. Use the pipe to separate several expressions. .withIncludeExpression(".*\\.JSON_COLUMN") ) ) )
See the configuration XSD and programmatic code generation for more details.
import org.jooq.meta.jaxb.* configuration { generator { database { forcedTypes { forcedType { // Specify the Java type of your custom type. This corresponds to the Converter's <U> type. userType = "com.example.MyType" // Apply the built in converter of type // // - org.jooq.jackson.extensions.converters.JSONtoJacksonConverter or // - org.jooq.jackson.extensions.converters.JSONBtoJacksonConverter. isJsonConverter = true // A Java regex matching fully-qualified columns, attributes, parameters. Use the pipe to separate several expressions. includeExpression = ".*\\.JSON_COLUMN" } } } } }
See the configuration XSD and gradle code generation for more details.
configuration { generator { database { forcedTypes { forcedType { // Specify the Java type of your custom type. This corresponds to the Converter's <U> type. userType = "com.example.MyType" // Apply the built in converter of type // // - org.jooq.jackson.extensions.converters.JSONtoJacksonConverter or // - org.jooq.jackson.extensions.converters.JSONBtoJacksonConverter. jsonConverter = true // A Java regex matching fully-qualified columns, attributes, parameters. Use the pipe to separate several expressions. includeExpression = ".*\\.JSON_COLUMN" } } } } }
See the configuration XSD and gradle code generation for more details.
generationTool { generator { database { forcedTypes { forcedType { // Specify the Java type of your custom type. This corresponds to the Converter's <U> type. userType = "com.example.MyType" // Apply the built in converter of type // // - org.jooq.jackson.extensions.converters.JSONtoJacksonConverter or // - org.jooq.jackson.extensions.converters.JSONBtoJacksonConverter. jsonConverter = true // A Java regex matching fully-qualified columns, attributes, parameters. Use the pipe to separate several expressions. includeExpression = ".*\\.JSON_COLUMN" } } } } }
See the configuration XSD and gradle code generation for more details.
As always, when regular expressions are used, they are regular expressions with default flags.
In order to access these converters, just add the following dependency to your project:
<dependency> <!-- Use org.jooq for the Open Source Edition org.jooq.pro for commercial editions with Java 11 support, org.jooq.pro-java-8 for commercial editions with Java 8 support, org.jooq.pro-java-6 for commercial editions with Java 6 support, org.jooq.trial for the free trial edition with Java 11 support, org.jooq.trial-java-8 for the free trial edition with Java 8 support, org.jooq.trial-java-6 for the free trial edition with Java 6 support Note: Only the Open Source Edition is hosted on Maven Central. Install the others locally using the provided scripts, or access them from here: https://repo.jooq.org See the JDK version support matrix here: https://www.jooq.org/download/support-matrix-jdk --> <groupId>org.jooq</groupId> <artifactId>jooq-jackson-extensions</artifactId> <version>3.19.13</version> </dependency>
dependencies { // Use org.jooq for the Open Source Edition // org.jooq.pro for commercial editions with Java 17 support, // org.jooq.pro-java-8 for commercial editions with Java 8 support, // org.jooq.pro-java-6 for commercial editions with Java 6 support, // org.jooq.trial for the free trial edition with Java 17 support, // org.jooq.trial-java-8 for the free trial edition with Java 8 support, // org.jooq.trial-java-6 for the free trial edition with Java 6 support // // Note: Only the Open Source Edition is hosted on Maven Central. // Install the others locally using the provided scripts, or access them from here: https://repo.jooq.org // See the JDK version support matrix here: https://www.jooq.org/download/support-matrix-jdk implementation("org.jooq:jooq-jackson-extensions:3.19.13") }
dependencies { // Use org.jooq for the Open Source Edition // org.jooq.pro for commercial editions with Java 17 support, // org.jooq.pro-java-8 for commercial editions with Java 8 support, // org.jooq.pro-java-6 for commercial editions with Java 6 support, // org.jooq.trial for the free trial edition with Java 17 support, // org.jooq.trial-java-8 for the free trial edition with Java 8 support, // org.jooq.trial-java-6 for the free trial edition with Java 6 support // // Note: Only the Open Source Edition is hosted on Maven Central. // Install the others locally using the provided scripts, or access them from here: https://repo.jooq.org // See the JDK version support matrix here: https://www.jooq.org/download/support-matrix-jdk implementation "org.jooq:jooq-jackson-extensions:3.19.13" }
For more details about how to match columns, please refer to the section about matching columns for forced types.
Feedback
Do you have any feedback about this page? We'd love to hear it!