Available in versions: Dev (3.18) | Latest (3.17)

This documentation is for the unreleased development version of jOOQ. Click on the above version links to get this documentation for a supported version of jOOQ.

JAXB converters

Applies to ✅ Open Source Edition   ✅ Express Edition   ✅ Professional Edition   ✅ Enterprise Edition

In case your database column is of type org.jooq.XML, you may want to attach a custom data type binding that is backed by JAXB. It is easy to achieve manually using a hand-written Converter, but you can also use the following convenience configuration:

XML (standalone and maven)
Programmatic
Gradle
<configuration xmlns="http://www.jooq.org/xsd/jooq-codegen-3.18.0.xsd">
  <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.impl.XMLtoJAXBConverter. -->
          <xmlConverter>true</xmlConverter>
            
          <!-- A Java regex matching fully-qualified columns, attributes, parameters. Use the pipe to separate several expressions. -->
          <includeExpression>.*\.XML_COLUMN</includeExpression>
        </forcedType>         
      </forcedTypes>
    </database>
  </generator>
</configuration>
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.impl.XMLtoJAXBConverter.
          .withXmlConverter(true)

          // A Java regex matching fully-qualified columns, attributes, parameters. Use the pipe to separate several expressions.
          .withIncludeExpression(".*\\.XML_COLUMN")
      )
    )
  )
myConfigurationName(sourceSets.main) {
  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.impl.XMLtoJAXBConverter.
          xmlConverter = true

          // A Java regex matching fully-qualified columns, attributes, parameters. Use the pipe to separate several expressions.
          includeExpression = '.*\\.XML_COLUMN'
        }
      }
    }
  }
}

As always, when regular expressions are used, they are regular expressions with default flags.

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!

The jOOQ Logo