Skip to content

Commit

Permalink
Replace obsolete/deprecated Kotlinx serial calls
Browse files Browse the repository at this point in the history
  • Loading branch information
gregorbg committed Jan 19, 2024
1 parent 8a3365c commit d1009d5
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import io.ktor.server.websocket.*
import io.ktor.websocket.*
import kotlinx.serialization.builtins.MapSerializer
import kotlinx.serialization.builtins.serializer
import kotlinx.serialization.encodeToString
import org.worldcubeassociation.tnoodle.server.RouteHandler
import org.worldcubeassociation.tnoodle.server.crypto.StringEncryption.encodeBase64
import org.worldcubeassociation.tnoodle.server.serial.JsonConfig
Expand Down Expand Up @@ -110,7 +111,7 @@ object JobSchedulingHandler : RouteHandler {
val request = job.extractFrame(call, frame)

val target = job.getTargetState(request)
val targetEnc = JsonConfig.SERIALIZER.encodeToString(MapSerializer(String.serializer(), Int.serializer()), target)
val targetEnc = JsonConfig.SERIALIZER.encodeToString<Map<String, Int>>(target)
send(targetEnc)

val (type, data) = job.channel(request, this)
Expand All @@ -127,7 +128,7 @@ object JobSchedulingHandler : RouteHandler {
close()
} catch (e: Throwable) {
val errorModel = e.asFrontendError()
val errorSerial = JsonConfig.SERIALIZER.encodeToString(FrontendErrorMessage.serializer(), errorModel)
val errorSerial = JsonConfig.SERIALIZER.encodeToString<FrontendErrorMessage>(errorModel)

send(MARKER_ERROR_MESSAGE)
send(errorSerial)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import io.ktor.server.request.*
import io.ktor.server.routing.*
import io.ktor.websocket.*
import kotlinx.coroutines.runBlocking
import kotlinx.serialization.encodeToString
import org.worldcubeassociation.tnoodle.server.RouteHandler
import org.worldcubeassociation.tnoodle.server.serial.JsonConfig
import org.worldcubeassociation.tnoodle.server.ServerEnvironmentConfig
Expand Down Expand Up @@ -36,7 +37,7 @@ class WcifHandler(val environmentConfig: ServerEnvironmentConfig) : RouteHandler

override suspend fun extractFrame(call: ApplicationCall, frame: Frame.Text): ScramblingJobData {
val frameText = frame.readText()
val requestData = JsonConfig.SERIALIZER.decodeFromString(WcifScrambleRequest.serializer(), frameText)
val requestData = JsonConfig.SERIALIZER.decodeFromString<WcifScrambleRequest>(frameText)

return call.verifyAndWrapWcifRequest(requestData)
}
Expand Down Expand Up @@ -116,7 +117,7 @@ class WcifHandler(val environmentConfig: ServerEnvironmentConfig) : RouteHandler
router.route("wcif") {
route("scrambles") {
val job = ScramblingJob { _, wcif, _ ->
val resultBytes = JsonConfig.SERIALIZER.encodeToString(Competition.serializer(), wcif)
val resultBytes = JsonConfig.SERIALIZER.encodeToString<Competition>(wcif)
ContentType.Application.Json to resultBytes.toByteArray()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org.worldcubeassociation.tnoodle.server.wcif.model
import kotlinx.serialization.*
import kotlinx.serialization.json.JsonObject
import kotlinx.serialization.json.buildJsonObject
import kotlinx.serialization.json.decodeFromJsonElement
import kotlinx.serialization.json.put
import org.worldcubeassociation.tnoodle.server.serial.JsonConfig
import org.worldcubeassociation.tnoodle.server.wcif.model.extension.ExtensionBuilder
Expand All @@ -17,6 +18,6 @@ data class Extension(val id: String, val specUrl: String, val data: JsonObject)
val mockData = buildJsonObject { put(JsonConfig.CLASS_DISCRIMINATOR, id) } + data
val mockExtension = JsonObject(mockData)

return JsonConfig.SERIALIZER.decodeFromJsonElement(ExtensionBuilder.serializer(), mockExtension) as? T
return JsonConfig.SERIALIZER.decodeFromJsonElement<ExtensionBuilder>(mockExtension) as? T
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.worldcubeassociation.tnoodle.server.zip

import kotlinx.serialization.encodeToString
import org.worldcubeassociation.tnoodle.server.serial.JsonConfig
import org.worldcubeassociation.tnoodle.server.pdf.ScrambleSheet
import org.worldcubeassociation.tnoodle.server.zip.util.StringUtil.toFileSafeString
Expand All @@ -15,7 +16,7 @@ data class InterchangeFolder(val wcif: Competition, val uniqueTitles: Map<String
val safeGlobalTitle = globalTitle.toFileSafeString()

val jsonInterchangeData = ZipInterchangeInfo(globalTitle, versionTag, generationDate, generationUrl, wcif)
val jsonStr = JsonConfig.SERIALIZER.encodeToString(ZipInterchangeInfo.serializer(), jsonInterchangeData)
val jsonStr = JsonConfig.SERIALIZER.encodeToString<ZipInterchangeInfo>(jsonInterchangeData)

val jsonpFileName = "$safeGlobalTitle.jsonp"
val jsonpStr = "var SCRAMBLES_JSON = $jsonStr;"
Expand Down

0 comments on commit d1009d5

Please sign in to comment.