-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changed default serialization mechanism to kotlinx serialization
- Loading branch information
Showing
45 changed files
with
140 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
backend/src/main/kotlin/dev/dres/api/rest/KotlinxJsonMapper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package dev.dres.api.rest | ||
|
||
import com.fasterxml.jackson.core.type.TypeReference | ||
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper | ||
import io.javalin.json.JsonMapper | ||
import kotlinx.serialization.KSerializer | ||
import kotlinx.serialization.SerializationException | ||
import kotlinx.serialization.json.Json | ||
import kotlinx.serialization.serializer | ||
import java.lang.reflect.Type | ||
|
||
object KotlinxJsonMapper : JsonMapper { | ||
|
||
private val fallbackMapper = jacksonObjectMapper() | ||
|
||
override fun <T : Any> fromJsonString(json: String, targetType: Type): T { | ||
|
||
return try { | ||
@Suppress("UNCHECKED_CAST") | ||
val serializer = serializer(targetType) as KSerializer<T> | ||
Json.decodeFromString(serializer, json) | ||
} catch (e: SerializationException) { | ||
null | ||
} catch (e: IllegalStateException) { | ||
null | ||
} ?: fallbackMapper.readValue(json, fallbackMapper.typeFactory.constructType(targetType)) | ||
|
||
} | ||
|
||
override fun toJsonString(obj: Any, type: Type): String { | ||
|
||
return try { | ||
val serializer = serializer(type) | ||
Json.encodeToString(serializer, obj) | ||
} catch (e: SerializationException) { | ||
null | ||
} catch (e: IllegalStateException) { | ||
null | ||
} ?: fallbackMapper.writeValueAsString(obj) | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
backend/src/main/kotlin/dev/dres/api/rest/types/collection/ApiMediaItemMetaDataEntry.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
package dev.dres.api.rest.types.collection | ||
|
||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class ApiMediaItemMetaDataEntry(val key: String, val value: String) |
2 changes: 2 additions & 0 deletions
2
backend/src/main/kotlin/dev/dres/api/rest/types/collection/time/ApiTemporalPoint.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
backend/src/main/kotlin/dev/dres/api/rest/types/collection/time/ApiTemporalRange.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
backend/src/main/kotlin/dev/dres/api/rest/types/evaluation/ApiEvaluationOverview.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
backend/src/main/kotlin/dev/dres/api/rest/types/evaluation/ApiTaskOverview.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
backend/src/main/kotlin/dev/dres/api/rest/types/evaluation/ApiTeamTaskOverview.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
package dev.dres.api.rest.types.evaluation | ||
|
||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class ApiTeamTaskOverview(val teamId: String, val tasks: List<ApiTaskOverview>) |
3 changes: 3 additions & 0 deletions
3
backend/src/main/kotlin/dev/dres/api/rest/types/evaluation/ApiViewerInfo.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,12 @@ | ||
package dev.dres.api.rest.types.evaluation | ||
|
||
import kotlinx.serialization.Serializable | ||
|
||
/** | ||
* Basic information regarding a viewer instance | ||
* | ||
* @author Ralph Gasser | ||
* @version 1.1.0 | ||
*/ | ||
@Serializable | ||
data class ApiViewerInfo(val viewersId: String, val username: String, val host: String, val ready: Boolean) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.