Verified Commit 3698d18e authored by Konstantin Kopper's avatar Konstantin Kopper
Browse files

Replace gson with kotlinx serialization in remaining classes

This concludes the migration from runtime reflection-based serialization to compile-time serializer deduction.
parent ee230d6f
Pipeline #27149 passed with stages
in 6 minutes and 8 seconds
......@@ -42,9 +42,6 @@ dependencies {
// Provides RichText TextAreas. Used for code input area.
implementation("org.fxmisc.richtext", "richtextfx", "0.10.6")
// Google GSON library for JSON
implementation("com.google.code.gson", "gson", "2.8.6")
// Apache Commons
implementation("commons-io", "commons-io", "2.8.0")
implementation("org.apache.commons", "commons-lang3", "3.12.0")
......
package com.pseuco.http
import com.google.gson.Gson
import com.pseuco.PseuCoComFile
import com.pseuco.PseuCoServer
import com.pseuco.api.PseuCoComExchange
......@@ -14,6 +13,8 @@ import io.ktor.routing.routing
import io.ktor.server.engine.ApplicationEngine
import io.ktor.server.engine.embeddedServer
import io.ktor.server.netty.Netty
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import java.util.Random
/**
......@@ -21,10 +22,18 @@ import java.util.Random
*
* @author Konstantin Kopper
* @since 2.0.0
* @property port The port the server is listening on (default: 28373).
* @constructor Creates a new server listening on the given port.
*/
class PseuCoHttpServer(private val port: Int = 28373) : PseuCoServer {
@Deprecated(
"HTTP communications are blocked by modern browsers, use WebSocket based approach instead.",
ReplaceWith("com.pseuco.websocket.PseuCoWebSocket"),
DeprecationLevel.WARNING
)
object PseuCoHttpServer : PseuCoServer {
/**
* The port the server is listening on (default: 28373).
*/
private const val port: Int = 28373
/**
* The files available when calling the server.
......@@ -49,6 +58,7 @@ class PseuCoHttpServer(private val port: Int = 28373) : PseuCoServer {
init {
server = embeddedServer(Netty, port) {
// install(ContentNegotiation) { json() }
routing {
get("/") {
call.respondText("Hello, world!", ContentType.Text.Html)
......@@ -61,7 +71,11 @@ class PseuCoHttpServer(private val port: Int = 28373) : PseuCoServer {
// Required by pseuCo.com
call.response.header("Access-Control-Allow-Origin", "*")
call.respondText(Gson().toJson(PseuCoComExchange(files[fileId]!!)), ContentType.Application.Json)
// call.respond(PseuCoComExchange(files[fileId]!!))
call.respondText(
Json.encodeToString(PseuCoComExchange(files[fileId]!!)),
contentType = ContentType.Application.Json
)
}
else -> {
call.response.status(HttpStatusCode.NotFound)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment