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

Apply various fixes to Kotlin Serialization modules #22715

Merged
merged 8 commits into from
Jan 7, 2022
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-reactive-kotlin-serialization-common</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-arc-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-kotlin-deployment</artifactId>
Expand All @@ -40,4 +44,4 @@
</plugins>
</build>

</project>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package io.quarkus.kotlin.serialization;

import static io.quarkus.deployment.annotations.ExecutionTime.STATIC_INIT;

import javax.inject.Singleton;

import io.quarkus.arc.deployment.SyntheticBeanBuildItem;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.annotations.Record;
import kotlinx.serialization.json.Json;

public class KotlinSerializationCommonProcessor {

@BuildStep
@Record(STATIC_INIT)
public SyntheticBeanBuildItem createJson(KotlinSerializerRecorder recorder, KotlinSerializationConfig config) {
return SyntheticBeanBuildItem
.configure(Json.class)
.scope(Singleton.class)
.supplier(recorder.configFactory(config))
.unremovable().done();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-kotlin</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-arc</artifactId>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlinx</groupId>
<artifactId>kotlinx-serialization-json</artifactId>
Expand All @@ -108,4 +112,4 @@
</dependency>
</dependencies>

</project>
</project>
Original file line number Diff line number Diff line change
@@ -1,28 +1,23 @@
package io.quarkus.kotlin.serialization.deployment;

import static io.quarkus.deployment.Feature.RESTEASY_REACTIVE_KOTLIN_SERIALIZATION;
import static io.quarkus.deployment.annotations.ExecutionTime.STATIC_INIT;
import static io.quarkus.resteasy.reactive.common.deployment.ServerDefaultProducesHandlerBuildItem.json;

import java.util.List;

import javax.inject.Singleton;
import javax.ws.rs.Priorities;
import javax.ws.rs.RuntimeType;
import javax.ws.rs.core.MediaType;

import io.quarkus.arc.deployment.AdditionalBeanBuildItem;
import io.quarkus.arc.deployment.SyntheticBeanBuildItem;
import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.annotations.Record;
import io.quarkus.deployment.builditem.FeatureBuildItem;
import io.quarkus.kotlin.serialization.KotlinSerializationConfig;
import io.quarkus.kotlin.serialization.KotlinSerializationMessageBodyReader;
import io.quarkus.kotlin.serialization.KotlinSerializationMessageBodyWriter;
import io.quarkus.kotlin.serialization.KotlinSerializerRecorder;
import io.quarkus.resteasy.reactive.common.deployment.ServerDefaultProducesHandlerBuildItem;
import io.quarkus.resteasy.reactive.spi.MessageBodyReaderBuildItem;
import io.quarkus.resteasy.reactive.spi.MessageBodyWriterBuildItem;
import kotlinx.serialization.json.Json;

public class KotlinSerializationProcessor {
@BuildStep
Expand All @@ -36,20 +31,12 @@ public void additionalProviders(
.setUnremovable().build());
additionalReaders.produce(new MessageBodyReaderBuildItem(
KotlinSerializationMessageBodyReader.class.getName(), Object.class.getName(), List.of(
MediaType.APPLICATION_JSON)));
MediaType.APPLICATION_JSON),
RuntimeType.SERVER, true, Priorities.USER));
additionalWriters.produce(new MessageBodyWriterBuildItem(
KotlinSerializationMessageBodyWriter.class.getName(), Object.class.getName(), List.of(
MediaType.APPLICATION_JSON)));
}

@BuildStep
@Record(STATIC_INIT)
public SyntheticBeanBuildItem createJson(KotlinSerializerRecorder recorder, KotlinSerializationConfig config) {
return SyntheticBeanBuildItem
.configure(Json.class)
.scope(Singleton.class)
.supplier(recorder.configFactory(config))
.unremovable().done();
MediaType.APPLICATION_JSON),
RuntimeType.SERVER, true, Priorities.USER));
}

@BuildStep
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import javax.inject.Inject
import javax.ws.rs.core.MediaType
import javax.ws.rs.core.MultivaluedMap

class KotlinSerializationMessageBodyReader(@Inject var json: Json) : AbstractJsonMessageBodyReader(), ServerMessageBodyReader<Any> {
override fun isReadable(type: Class<*>, genericType: Type, annotations: Array<Annotation>, mediaType: MediaType) =
class KotlinSerializationMessageBodyReader(private val json: Json) : AbstractJsonMessageBodyReader(), ServerMessageBodyReader<Any> {
override fun isReadable(type: Class<*>, genericType: Type, annotations: Array<Annotation>?, mediaType: MediaType) =
isReadable(mediaType, type)

override fun isReadable(type: Class<*>, genericType: Type, lazyMethod: ResteasyReactiveResourceInfo, mediaType: MediaType) =
Expand All @@ -42,4 +42,4 @@ class KotlinSerializationMessageBodyReader(@Inject var json: Json) : AbstractJso
return if (StreamUtil.isEmpty(entityStream)) null else
json.decodeFromStream(serializer(type), entityStream)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import javax.ws.rs.core.MultivaluedMap

@Produces("application/json", "application/*+json", "text/json")
@OptIn(ExperimentalSerializationApi::class)
class KotlinSerializationMessageBodyWriter(@Inject var json: Json) : AllWriteableMessageBodyWriter() {
class KotlinSerializationMessageBodyWriter(private val json: Json) : AllWriteableMessageBodyWriter() {
override fun writeTo(
o: Any, type: Class<*>, genericType: Type, annotations: Array<Annotation>, mediaType: MediaType,
httpHeaders: MultivaluedMap<String, Any>, entityStream: OutputStream
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-rest-client-reactive-kotlin-serialization</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-reactive-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-kotlin-deployment</artifactId>
Expand All @@ -35,6 +31,10 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-rest-client-reactive-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-reactive-kotlin-serialization-common-deployment</artifactId>
</dependency>

<!-- test dependencies: -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,21 @@
package io.quarkus.rest.client.reactive.kotlin.deployment;

import static io.quarkus.deployment.Feature.REST_CLIENT_REACTIVE_KOTLIN_SERIALIZATION;
import static io.quarkus.deployment.annotations.ExecutionTime.STATIC_INIT;

import java.util.Collections;

import javax.inject.Singleton;
import javax.ws.rs.Priorities;
import javax.ws.rs.RuntimeType;
import javax.ws.rs.core.MediaType;

import io.quarkus.arc.deployment.AdditionalBeanBuildItem;
import io.quarkus.arc.deployment.SyntheticBeanBuildItem;
import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.annotations.Record;
import io.quarkus.deployment.builditem.FeatureBuildItem;
import io.quarkus.kotlin.serialization.KotlinSerializationConfig;
import io.quarkus.kotlin.serialization.KotlinSerializerRecorder;
import io.quarkus.rest.client.reactive.kotlin.runtime.serializers.ClientKotlinMessageBodyReader;
import io.quarkus.rest.client.reactive.kotlin.runtime.serializers.ClientKotlinMessageBodyWriter;
import io.quarkus.resteasy.reactive.spi.MessageBodyReaderBuildItem;
import io.quarkus.resteasy.reactive.spi.MessageBodyWriterBuildItem;
import kotlinx.serialization.json.Json;

public class RestClientReactiveKotlinSerializationProcessor {

Expand All @@ -41,19 +36,9 @@ void additionalProviders(

additionalReaders
.produce(new MessageBodyReaderBuildItem(ClientKotlinMessageBodyReader.class.getName(), Object.class.getName(),
Collections.singletonList(MediaType.APPLICATION_JSON)));
Collections.singletonList(MediaType.APPLICATION_JSON), RuntimeType.CLIENT, true, Priorities.USER));
additionalWriters
.produce(new MessageBodyWriterBuildItem(ClientKotlinMessageBodyWriter.class.getName(), Object.class.getName(),
Collections.singletonList(MediaType.APPLICATION_JSON)));
}

@BuildStep
@Record(STATIC_INIT)
public SyntheticBeanBuildItem createJson(KotlinSerializerRecorder recorder, KotlinSerializationConfig config) {
return SyntheticBeanBuildItem
.configure(Json.class)
.scope(Singleton.class)
.supplier(recorder.configFactory(config))
.unremovable().done();
Collections.singletonList(MediaType.APPLICATION_JSON), RuntimeType.CLIENT, true, Priorities.USER));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-reactive-kotlin-serialization-common</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-reactive</artifactId>
</dependency>
</dependencies>

<build>
Expand Down Expand Up @@ -100,4 +96,4 @@
</plugin>
</plugins>
</build>
</project>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import javax.ws.rs.core.MultivaluedMap
import javax.ws.rs.ext.MessageBodyReader

@OptIn(ExperimentalSerializationApi::class)
class ClientKotlinMessageBodyReader(@Inject val json: Json) : MessageBodyReader<Any> {
class ClientKotlinMessageBodyReader(private val json: Json) : MessageBodyReader<Any> {
override fun isReadable(type: Class<*>?, generic: Type?, annotations: Array<out Annotation>?, mediaType: MediaType?) = true

override fun readFrom(
Expand All @@ -23,4 +23,4 @@ class ClientKotlinMessageBodyReader(@Inject val json: Json) : MessageBodyReader<
return if (StreamUtil.isEmpty(entityStream)) null else
json.decodeFromStream(serializer(generic), entityStream)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import javax.ws.rs.core.MultivaluedMap
import javax.ws.rs.ext.MessageBodyWriter

@OptIn(ExperimentalSerializationApi::class)
class ClientKotlinMessageBodyWriter(@Inject val json: Json) : MessageBodyWriter<Any> {
class ClientKotlinMessageBodyWriter(private val json: Json) : MessageBodyWriter<Any> {
override fun isWriteable(type: Class<*>, genericType: Type, annotations: Array<out Annotation>?, mediaType: MediaType?) = true

override fun writeTo(
Expand All @@ -21,4 +21,4 @@ class ClientKotlinMessageBodyWriter(@Inject val json: Json) : MessageBodyWriter<
) {
json.encodeToStream(serializer(genericType), t, entityStream)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
<name>Quarkus - Integration Tests - REST Client Reactive Kotlin Serialization</name>

<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-reactive-kotlin-serialization</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-rest-client-reactive-kotlin-serialization</artifactId>
Expand Down Expand Up @@ -40,6 +44,19 @@
</dependency>

<!-- Minimal test dependencies to *-deployment artifacts for consistent build order -->
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-reactive-kotlin-serialization-deployment</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-rest-client-reactive-kotlin-serialization-deployment</artifactId>
Expand Down