question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

OpenApiOptions fails to initialize without jackson-module-kotlin

See original GitHub issue

Actual behavior (the bug) When you don’t have jackson-module-kotlin installed, initializing OpenApiOptions fails before you can specify a replacement ToJsonMapper.

Exception in thread "main" java.lang.NoClassDefFoundError: com/fasterxml/jackson/module/kotlin/ExtensionsKt
	at io.javalin.plugin.openapi.jackson.JacksonToJsonMapper.<clinit>(JacksonToJsonMapper.kt:12)
	at io.javalin.plugin.openapi.OpenApiOptions.<init>(OpenApiOptions.kt:42)
	at io.javalin.plugin.openapi.OpenApiOptions.<init>(OpenApiOptions.kt:48)
	at io.javalin.plugin.openapi.OpenApiOptions.<init>(OpenApiOptions.kt:49)
	...........registerSwagger(Server.java:171)
        ..........
Caused by: java.lang.ClassNotFoundException: com.fasterxml.jackson.module.kotlin.ExtensionsKt
	at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
	... 7 more

Expected behavior The OpenApiOptions should allow me to specify an alternate ToJsonMapper before trying to initialize the default one provided by the missing jackson-module-kotlin.

To Reproduce

private void registerSwagger(Javalin app) {
    final Info applicationInfo = new Info()
                .version("1.0")
                .description("My Application");
    final OpenApiOptions options = new OpenApiOptions(applicationInfo).path("/swagger-docs");

    final Gson gson = new Gson();
    options.setToJsonMapper(gson::toJson);

    app.config.registerPlugin(new OpenApiPlugin(options));
}

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
tipsycommented, Jun 18, 2019

Yes, in the weekend 😃

0reactions
agugliecommented, Jul 28, 2019

Hi 😄 Was it fixed? I think I’m still getting the same error:

    void run() {
        Gson gson = new GsonBuilder().create();
        JavalinJson.setFromJsonMapper(gson::fromJson);
        JavalinJson.setToJsonMapper(gson::toJson);
        Javalin app = Javalin.create(config -> config.registerPlugin(
                new OpenApiPlugin(
                        new OpenApiOptions(new Info().version("1.0").description("My Application"))
                                .path("/swagger-docs")
                                .toJsonMapper(gson::toJson)
                ))).start();
        app.get("/", ctx -> ctx.result("Hello World"));
    }

I’m getting:

[qtp712256162-15] ERROR io.javalin.Javalin - Exception occurred while servicing http-request
java.lang.NoClassDefFoundError: com/fasterxml/jackson/module/kotlin/ExtensionsKt
	at io.javalin.plugin.openapi.jackson.JacksonToJsonMapper$objectMapper$2.invoke(JacksonToJsonMapper.kt:12)
	at io.javalin.plugin.openapi.jackson.JacksonToJsonMapper$objectMapper$2.invoke(JacksonToJsonMapper.kt:11)
	at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
	at io.javalin.plugin.openapi.jackson.JacksonToJsonMapper.getObjectMapper(JacksonToJsonMapper.kt)

Caused by: java.lang.ClassNotFoundException: com.fasterxml.jackson.module.kotlin.ExtensionsKt
	at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)

My pom.xml section:

    <dependencies>
        <dependency>
            <groupId>io.javalin</groupId>
            <artifactId>javalin</artifactId>
            <version>3.3.0</version>
        </dependency>
        <dependency>
            <groupId>io.swagger.core.v3</groupId>
            <artifactId>swagger-models</artifactId>
            <version>2.0.8</version>
        </dependency>
        <dependency>
            <groupId>cc.vileda</groupId>
            <artifactId>kotlin-openapi3-dsl</artifactId>
            <version>0.20.1</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-simple</artifactId>
            <version>1.7.26</version>
        </dependency>
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>2.8.5</version>
        </dependency>
    </dependencies>

Running on openjdk version “1.8.0_222”

Read more comments on GitHub >

github_iconTop Results From Across the Web

OpenApiOptions fails to initialize without jackson-module-kotlin
When you don't have jackson-module-kotlin installed, initializing OpenApiOptions fails before you can specify a replacement ToJsonMapper .
Read more >
openapi springboot generator jackson no String-argument ...
This creates model classes with JsonNullable<String> for nullable fields. However I'm getting a Jackson type definition error while POST request ...
Read more >
F.A.Q - Springdoc-openapi
How to Integrate Open API 3 with Spring project (not Spring Boot)?. When your application is using spring without (spring-boot), you need to...
Read more >
Micronaut Open API - OpenAPI/Swagger Support
To create a project with OpenAPI/Swagger support using the Micronaut CLI, supply the openapi feature to the features flag. For example:.
Read more >
Jackson Dependency Issue in Spring Boot with Maven Build
Jackson is currently the leading option for parsing JSON in Java. ... Could not initialize class com.fasterxml.jackson.databind.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found