Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resteasy reactive kotlin serialization not completely configured after generating app from code.quarkus.io #33622

Closed
janpk opened this issue May 26, 2023 · 13 comments · Fixed by #36201
Labels
Milestone

Comments

@janpk
Copy link

janpk commented May 26, 2023

Describe the bug

Creating an app through code.quarkus.io with

  • kotlin
  • resteasy reactive kotlin serialization
  • maven

do not configure the kotlin-maven-plugin to use kotlinx-serialization.

Without doing this, kotlin serialization will not work, and the following error will be given when returning an object where content type is application_json

kotlinx.serialization.SerializationException: Serializer for class 'Result' is not found.
Please ensure that class is marked as '@Serializable' and that the serialization compiler plugin is applied.

        at kotlinx.serialization.internal.PlatformKt.serializerNotRegistered(Platform.kt:31)

Expected behavior

When selecting the resteasy reactive kotlin serialization extension, the kotlin-maven-plugin should also be configured in pom.xml.

     <plugin>
        <groupId>org.jetbrains.kotlin</groupId>
        <artifactId>kotlin-maven-plugin</artifactId>
        <version>${kotlin.version}</version>
        <executions>
          <execution>
            <id>compile</id>
            <goals>
              <goal>compile</goal>
            </goals>
          </execution>
          <execution>
            <id>test-compile</id>
            <goals>
              <goal>test-compile</goal>
            </goals>
          </execution>
        </executions>
        <dependencies>
          <dependency>
            <groupId>org.jetbrains.kotlin</groupId>
            <artifactId>kotlin-maven-allopen</artifactId>
            <version>${kotlin.version}</version>
          </dependency>
          <dependency>
            <groupId>org.jetbrains.kotlin</groupId>
            <artifactId>kotlin-maven-serialization</artifactId>
            <version>${kotlin.version}</version>
          </dependency>
        </dependencies>
        <configuration>
          <javaParameters>true</javaParameters>
          <jvmTarget>17</jvmTarget>
          <compilerPlugins>
            <plugin>all-open</plugin>
            <plugin>kotlinx-serialization</plugin>
          </compilerPlugins>
          <pluginOptions>
            <option>all-open:annotation=jakarta.ws.rs.Path</option>
            <option>all-open:annotation=jakarta.enterprise.context.ApplicationScoped</option>
            <option>all-open:annotation=io.quarkus.test.junit.QuarkusTest</option>
          </pluginOptions>
        </configuration>
      </plugin>

Actual behavior

The generated kotlin-maven-plugin in pom.xml is without the kotlinx.serialization plugin

      <plugin>
        <groupId>org.jetbrains.kotlin</groupId>
        <artifactId>kotlin-maven-plugin</artifactId>
        <version>${kotlin.version}</version>
        <executions>
          <execution>
            <id>compile</id>
            <goals>
              <goal>compile</goal>
            </goals>
          </execution>
          <execution>
            <id>test-compile</id>
            <goals>
              <goal>test-compile</goal>
            </goals>
          </execution>
        </executions>
        <dependencies>
          <dependency>
            <groupId>org.jetbrains.kotlin</groupId>
            <artifactId>kotlin-maven-allopen</artifactId>
            <version>${kotlin.version}</version>
          </dependency>
        </dependencies>
        <configuration>
          <javaParameters>true</javaParameters>
          <jvmTarget>17</jvmTarget>
          <compilerPlugins>
            <plugin>all-open</plugin>
          </compilerPlugins>
          <pluginOptions>
            <option>all-open:annotation=jakarta.ws.rs.Path</option>
            <option>all-open:annotation=jakarta.enterprise.context.ApplicationScoped</option>
            <option>all-open:annotation=io.quarkus.test.junit.QuarkusTest</option>
          </pluginOptions>
        </configuration>
      </plugin>

How to Reproduce?

  1. Use code.quarkus.io, select maven as build tool and select the kotlin and the resteasy-reactive-kotlin-serialization extension
  2. Change GreetingResource.kt generated starter code to
@Path("/hello")
class GreetingResource {

    @GET
    @Produces(MediaType.APPLICATION_JSON)
    fun hello() = Result("Hello from RESTEasy Reactive")
}

@Serializable
data class Result(val greeting : String)

Running

./mvnw test

results in

kotlinx.serialization.SerializationException: Serializer for class 'Result' is not found.
Please ensure that class is marked as '@Serializable' and that the serialization compiler plugin is applied.

        at kotlinx.serialization.internal.PlatformKt.serializerNotRegistered(Platform.kt:31)

Output of uname -a or ver

No response

Output of java -version

No response

GraalVM version (if different from Java)

No response

Quarkus version or git rev

No response

Build tool (ie. output of mvnw --version or gradlew --version)

No response

Additional information

No response

@janpk janpk added the kind/bug Something isn't working label May 26, 2023
@quarkus-bot
Copy link

quarkus-bot bot commented May 26, 2023

/cc @FroMage (resteasy-reactive), @Sgitario (resteasy-reactive), @evanchooly (kotlin), @geoand (kotlin,resteasy-reactive), @stuartwdouglas (resteasy-reactive)

@geoand
Copy link
Contributor

geoand commented May 26, 2023

Makes perfect sense, thanks for reporting!

@bulldog98
Copy link
Contributor

Had a short look and it seems this also happens with gradle, should I open a seperate ticket for that?

@geoand
Copy link
Contributor

geoand commented May 26, 2023

No need, this ticket is fine

@geoand
Copy link
Contributor

geoand commented May 29, 2023

cc @ia3andy

@geoand
Copy link
Contributor

geoand commented Jun 27, 2023

@ia3andy given how many people use Kotlin in Quarkus, I think this should be done. WDYT?

@ia3andy
Copy link
Contributor

ia3andy commented Jun 27, 2023

@geoand @janpk would it be a problem to have this dep (even when the kotlin serialization extension is not there)?:

<dependency>
            <groupId>org.jetbrains.kotlin</groupId>
            <artifactId>kotlin-maven-serialization</artifactId>
            <version>${kotlin.version}</version>
          </dependency>

Else we could add a "if" condition based on the selected extensions, but this is a bit fragile (same for gradle I guess)

@geoand
Copy link
Contributor

geoand commented Jun 27, 2023

As far as I can tell, the issue is about configuring the Kotlin plugin, not about adding a dependency

@ia3andy
Copy link
Contributor

ia3andy commented Jun 27, 2023

ah yes I missed than one:

<compilerPlugins>
            <plugin>all-open</plugin>
            <plugin>kotlinx-serialization</plugin>
          </compilerPlugins>

So it's both, then we will need a if I believe

@ia3andy
Copy link
Contributor

ia3andy commented Jun 27, 2023

are those two extensions the trigger to having this config?
https://code.quarkus.io/?extension-search=origin:platform%20serialization%20kotlin

@geoand
Copy link
Contributor

geoand commented Jun 27, 2023

correct!

@im-bravo
Copy link

Hi, team
Any solution about this issue ?

@ia3andy
Copy link
Contributor

ia3andy commented Sep 28, 2023

I will fix it now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants