Skip to content
This repository has been archived by the owner on May 22, 2023. It is now read-only.

Commit

Permalink
Dependency updates, fix to match new ktor API.
Browse files Browse the repository at this point in the history
  • Loading branch information
gchallen committed Sep 5, 2022
1 parent 3b53a3e commit 2b13e43
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 17 deletions.
6 changes: 3 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
kotlin("jvm") version "1.6.21" apply false
id("org.jmailen.kotlinter") version "3.10.0" apply false
kotlin("jvm") version "1.7.10" apply false
id("org.jmailen.kotlinter") version "3.11.1" apply false
id("com.github.ben-manes.versions") version "0.42.0"
}
subprojects {
group = "com.github.cs125-illinois"
version = "2022.4.0"
version = "2022.9.0"
tasks.withType<KotlinCompile> {
kotlinOptions {
jvmTarget = JavaVersion.VERSION_16.toString()
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
8 changes: 4 additions & 4 deletions library/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ plugins {
dependencies {
kaptTest("com.squareup.moshi:moshi-kotlin-codegen:1.13.0")

implementation("io.ktor:ktor-server-core:2.0.0")
implementation("io.ktor:ktor-server-content-negotiation:2.0.0")
implementation("io.ktor:ktor-server-core:2.1.0")
implementation("io.ktor:ktor-server-content-negotiation:2.1.0")
implementation("com.squareup.moshi:moshi-kotlin:1.13.0")
implementation("com.squareup.okio:okio:3.1.0")
implementation("com.squareup.okio:okio:3.2.0")

testImplementation(kotlin("test"))
testImplementation("com.google.truth:truth:1.1.3")
testImplementation("io.ktor:ktor-server-test-host:2.0.0")
testImplementation("io.ktor:ktor-server-test-host:2.1.0")
}
tasks {
val sourcesJar by creating(Jar::class) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
package com.ryanharter.ktor.moshi

import com.squareup.moshi.Moshi
import io.ktor.content.TextContent
import io.ktor.http.ContentType
import io.ktor.http.content.TextContent
import io.ktor.http.withCharset
import io.ktor.serialization.ContentConverter
import io.ktor.server.plugins.contentnegotiation.ContentNegotiationConfig
import io.ktor.util.reflect.TypeInfo
import io.ktor.utils.io.ByteReadChannel
import io.ktor.utils.io.charsets.Charset
import io.ktor.utils.io.jvm.javaio.toInputStream
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import okio.buffer
import okio.source
import java.nio.charset.Charset

class MoshiConverter(private val moshi: Moshi = Moshi.Builder().build()) : ContentConverter {
override suspend fun deserialize(charset: Charset, typeInfo: TypeInfo, content: ByteReadChannel): Any? {
Expand All @@ -24,12 +24,18 @@ class MoshiConverter(private val moshi: Moshi = Moshi.Builder().build()) : Conte
}
}

override suspend fun serialize(
override suspend fun serializeNullable(
contentType: ContentType,
charset: Charset,
typeInfo: TypeInfo,
value: Any
) = TextContent(moshi.adapter(value.javaClass).toJson(value), contentType.withCharset(charset))
value: Any?
) = TextContent(
moshi.adapter(
value?.javaClass
?: Any::class.java
).nullSafe().toJson(value),
contentType.withCharset(charset)
)
}

/**
Expand Down
8 changes: 4 additions & 4 deletions sample/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ dependencies {
kapt("com.squareup.moshi:moshi-kotlin-codegen:1.13.0")

implementation(project(":library"))
implementation("io.ktor:ktor-server-netty:2.0.0")
implementation("io.ktor:ktor-server-content-negotiation:2.0.0")
implementation("io.ktor:ktor-server-call-logging:2.0.0")
implementation("ch.qos.logback:logback-classic:1.2.11")
implementation("io.ktor:ktor-server-netty:2.1.0")
implementation("io.ktor:ktor-server-content-negotiation:2.1.0")
implementation("io.ktor:ktor-server-call-logging:2.1.0")
implementation("ch.qos.logback:logback-classic:1.4.0")
implementation("com.squareup.moshi:moshi-adapters:1.13.0")
implementation("com.squareup.moshi:moshi:1.13.0")
implementation("com.squareup.moshi:moshi-kotlin:1.13.0")
Expand Down

0 comments on commit 2b13e43

Please sign in to comment.