Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4791 pages
Node.js, PHP and APIs

Classes made by openapi-generator-maven-plugin do not compile

Your error

package org.openapitools.jackson.nullable does not exist3 more lines it can show

Fix it fast

Most common cause, 1 of 3

openApiNullable is on but jackson-databind-nullable is not in the pom

Add the library, or turn the option off in configOptions if you do not need to tell an explicit null apart from a missing field.

Fix
<dependency>
  <groupId>org.openapitools</groupId>
  <artifactId>jackson-databind-nullable</artifactId>
  <version>0.2.13</version>
</dependency>

<!-- or, inside the plugin's <configOptions> -->
<openApiNullable>false</openApiNullable>
Did this fix it?
Full steps for this cause: check, fix, verify

Short answer

Code from openapi-generator-maven-plugin fails with cannot find symbol when the generator's defaults expect libraries your pom lacks. openApiNullable is on by default and needs jackson-databind-nullable; useBeanValidation is on and needs spring-boot-starter-validation; useSpringBoot3 decides javax versus jakarta imports. Add the dependency or switch the option off. Applies to plugin 7.27.0 and Spring Boot 3.5 or 4.2.

  • Applies to openapi-generator-maven-plugin 7.27.0 (spring generator), jackson-databind-nullable 0.2.13, Spring Boot 3.5 and 4.2, Maven 3.9
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Which cause do you have?

Compile once and read the first missing package in the output. The package name points straight at the cause: org.openapitools.jackson.nullable, a validation package, or a javax import inside a jakarta project.

Run this first
mvn -q compile 2>&1 | grep -m 5 -E "does not exist|cannot find symbol"

Then find the line you see in this list and open its fix:

  1. 1openApiNullable is on but jackson-databind-nullable is not in the pomThe first error is package org.openapitools.jackson.nullable does not exist, followed by cannot find symbol JsonNullable
  2. 2Bean Validation annotations are generated but no validation library is presentErrors name jakarta.validation or symbols such as Valid, NotNull, Size and Pattern
  3. 3Generated imports use javax while the project is on jakarta, or the reverseThe missing package starts with javax. in a Spring Boot 3 or 4 project, or with jakarta. in an old Spring Boot 2 project

What does the error look like?

  • package org.openapitools.jackson.nullable does not exist
  • symbol: class JsonNullable
  • package jakarta.validation.constraints does not exist
  • package javax.validation does not exist

Cause 1 of 3

openApiNullable is on but jackson-databind-nullable is not in the pom

You seeThe first error is package org.openapitools.jackson.nullable does not exist, followed by cannot find symbol JsonNullable

Check

The Spring generator's openApiNullable option defaults to true, which enables the OpenAPI Jackson Nullable library in generated models, so they import its JsonNullable wrapper. That class lives in the separate jackson-databind-nullable artifact, which the project's own pom has to declare; the generator's Spring Boot 3 sample pom lists it explicitly.

Check
mvn dependency:tree -Dincludes=org.openapitools:jackson-databind-nullable

Fix

Add the library, or turn the option off in configOptions if you do not need to tell an explicit null apart from a missing field.

Fix
<dependency>
  <groupId>org.openapitools</groupId>
  <artifactId>jackson-databind-nullable</artifactId>
  <version>0.2.13</version>
</dependency>

<!-- or, inside the plugin's <configOptions> -->
<openApiNullable>false</openApiNullable>

Verify

mvn compile finishes, and the dependency tree now lists jackson-databind-nullable.

Verify
mvn -q compile && echo compiled

Confirmed by openapi-generator.tech

Did this fix it?

Cause 2 of 3

Bean Validation annotations are generated but no validation library is present

You seeErrors name jakarta.validation or symbols such as Valid, NotNull, Size and Pattern

Check

useBeanValidation defaults to true, which puts @Valid, @NotNull and similar annotations on the generated API and models. Those jakarta.validation types come from a Bean Validation jar, which Spring Boot normally gets through spring-boot-starter-validation; the generator's sample pom adds that starter next to the web starter.

Check
mvn dependency:tree -Dincludes=jakarta.validation

Fix

Add the Spring Boot validation starter, which also brings a validator implementation. If you want no validation in generated code, set useBeanValidation to false instead.

Fix
<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-validation</artifactId>
</dependency>

Verify

The validation errors disappear from the build output.

Verify
mvn -q compile && echo compiled

Confirmed by raw.githubusercontent.com

Did this fix it?

Cause 3 of 3

Generated imports use javax while the project is on jakarta, or the reverse

You seeThe missing package starts with javax. in a Spring Boot 3 or 4 project, or with jakarta. in an old Spring Boot 2 project

Check

Spring Boot 3 and later use the Jakarta EE namespace. The generator picks javax or jakarta imports from useSpringBoot3, useSpringBoot4 and useJakartaEe; a config that sets useSpringBoot3 to false, or an old pinned plugin version, keeps writing javax imports.

Check
grep -nE "useSpringBoot3|useSpringBoot4|useJakartaEe|openapi-generator-maven-plugin" pom.xml

Fix

Match the option to your Spring Boot line. Use useSpringBoot3 for Boot 3 and useSpringBoot4 for Boot 4; both switch on useJakartaEe. Update the plugin to the current release while you are there, then clean so stale sources are regenerated.

Fix
<configOptions>
  <useSpringBoot3>true</useSpringBoot3>
  <!-- Spring Boot 4: <useSpringBoot4>true</useSpringBoot4> -->
</configOptions>

mvn clean compile

Verify

The generated sources under target/generated-sources import jakarta packages only.

Verify
grep -rl "import javax.validation" target/generated-sources | wc -l

Confirmed by openapi-generator.tech

Did this fix it?

How do I stop it coming back?

  • Write every configOption you rely on into the pom explicitly, so a plugin upgrade that changes a default cannot change your imports.
  • Copy the dependency block from the generator's sample pom for your Spring Boot line when you add the plugin.
  • Run mvn clean compile in CI, so a stale generated-sources folder never hides a missing dependency.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine on the same stack: Dispatch Pro.

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.