javajsonmoduleyasson

Java 17 module project (maven), when reading Json NoClassDefFoundError: jakarta/json/JsonConfig$KeyStrategy


This is not my first module based project but I am very shakey on how it all works, I am sure this is my issue. Project Jigsaw seems like smoke and mirrors to me at the moment. Any assistance would be greatly appreciated.

Here is where the exception happens:

result.payload().ifPresent(payloadString -> {

        final var jsonReader = Json.createReader(new StringReader(payloadString));
        final var jsonObject = jsonReader.readObject(); <== error here
        jsonReader.close();

My module-info.java

    module com.mymodule.pocclient {
    requires javafx.controls;
    requires javafx.fxml;
    requires jcip.annotations;
    requires java.logging;
    requires org.controlsfx.controls;
    requires com.dlsc.formsfx;
    requires jakarta.json.bind;
    requires jakarta.json;
    requires org.eclipse.yasson;
    requires org.eclipse.parsson;
    requires static lombok;
    requires jjwt.api;
    requires com.mymodule.cryptography;


    opens com.mymodule.pocclient.controllers to javafx.fxml;
    opens com.mymodule.pocclient.model to javafx.base, org.eclipse.yasson;
    opens com.mymodule.pocclient to javafx.fxml;
    opens com.mymodule.pocclient.network to org.eclipse.parsson;

    exports com.mymodule.pocclient;
    exports com.mymodule.pocclient.controllers;
}

The exception:

java.lang.NoClassDefFoundError: jakarta/json/JsonConfig$KeyStrategy
at org.eclipse.parsson@1.1.0/org.eclipse.parsson.JsonObjectBuilderImpl$DuplicateStrategy.<clinit>(JsonObjectBuilderImpl.java:373)
at org.eclipse.parsson@1.1.0/org.eclipse.parsson.JsonObjectBuilderImpl.<init>(JsonObjectBuilderImpl.java:59)
at org.eclipse.parsson@1.1.0/org.eclipse.parsson.JsonParserImpl.getObject(JsonParserImpl.java:171)
at org.eclipse.parsson@1.1.0/org.eclipse.parsson.JsonReaderImpl.readObject(JsonReaderImpl.java:103)
at com.lifelenz.poclifelenzclient/com.mymodule.pocclient.controllers.LoginController.lambda$processAuthenticatedUser$0(LoginController.java:121)

dependencies from my pom file (not sure how much is relevant)

<dependency>
        <groupId>com.lifelenz.jmsa</groupId>
        <artifactId>cryptography</artifactId>
        <version>0.1.0</version>
    </dependency>
    <dependency>
        <groupId>org.eclipse.parsson</groupId>
        <artifactId>parsson</artifactId>
        <version>1.1.0</version>
    </dependency>

    <dependency>
        <groupId>jakarta.json</groupId>
        <artifactId>jakarta.json-api</artifactId>
        <version>2.1.0</version>
    </dependency>
    <dependency>
        <groupId>org.mapstruct</groupId>
        <artifactId>mapstruct-processor</artifactId>
        <version>1.3.0.Final</version>
    </dependency>
    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <version>1.18.24</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>jakarta.json.bind</groupId>
        <artifactId>jakarta.json.bind-api</artifactId>
        <version>3.0.0</version>
    </dependency>
    <dependency>
        <groupId>org.eclipse</groupId>
        <artifactId>yasson</artifactId>
        <version>3.0.0-RC2</version>
    </dependency>
    <dependency>
        <groupId>org.glassfish</groupId>
        <artifactId>jakarta.json</artifactId>
        <version>2.0.1</version>
    </dependency>
    <dependency>
        <groupId>io.jsonwebtoken</groupId>
        <artifactId>jjwt-api</artifactId>
        <version>0.11.5</version>
    </dependency>
    <dependency>
        <groupId>io.jsonwebtoken</groupId>
        <artifactId>jjwt-impl</artifactId>
        <version>0.11.5</version>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>io.jsonwebtoken</groupId>
        <artifactId>jjwt-jackson</artifactId> <!-- or jjwt-gson if Gson is preferred -->
        <version>0.11.5</version>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>net.jcip</groupId>
        <artifactId>jcip-annotations</artifactId>
        <version>1.0</version>
    </dependency>
    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-controls</artifactId>
        <version>${javafx.version}</version>
    </dependency>
    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-fxml</artifactId>
        <version>${javafx.version}</version>
    </dependency>
    <dependency>
        <groupId>javax.validation</groupId>
        <artifactId>validation-api</artifactId>
        <version>2.0.1.Final</version>
    </dependency>
    <dependency>
        <groupId>org.controlsfx</groupId>
        <artifactId>controlsfx</artifactId>
        <version>11.1.1</version>
    </dependency>
    <dependency>
        <groupId>com.dlsc.formsfx</groupId>
        <artifactId>formsfx-core</artifactId>
        <version>11.5.0</version>
        <exclusions>
            <exclusion>
                <groupId>org.openjfx</groupId>
                <artifactId>*</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-api</artifactId>
        <version>${junit.version}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-engine</artifactId>
        <version>${junit.version}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-graphics</artifactId>
        <version>18.0.1</version>
    </dependency>

Solution

  • Removing the following dependency resolved the issue.

        <dependency>
            <groupId>org.glassfish</groupId>
            <artifactId>jakarta.json</artifactId>
            <version>2.0.1</version>
        </dependency>
    

    I assume it was clashing with parsson.