Skip to content

Commit

Permalink
WIP: KSerialize
Browse files Browse the repository at this point in the history
  • Loading branch information
Bram-- committed Mar 23, 2024
1 parent 9cedd8f commit bde59f7
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 11 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ publishing {
create<MavenPublication>("mavenJava") {
groupId = "org.audux.bgg"
artifactId = "bggclient"
version = "0.7.1.4"
version = "0.7.1.6"

pom {
name = "Unofficial JVM BGG client"
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ ktor = "2.3.8"
org-jetbrains-dokka = "1.9.10"
org-jetbrains-kotlin-jvm = "1.9.22"
org-jetbrains-kotlin-jdk8 = "1.8.0"
serialization = "1.6.3"
serialization = "1.5.0"
slf4j = "2.0.12"
truth = "1.4.1"

Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/org/audux/bgg/response/KSerializers.kt
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class URISerializer : KSerializer<URI> {
}

@OptIn(InternalSerializationApi::class)
class PollSerializer<T : Poll>(valueSerializer: KSerializer<T>) : KSerializer<Poll> {
class PollSerializer : KSerializer<Poll> {
private val serializer =
SealedClassSerializer(
"Poll",
Expand All @@ -62,7 +62,7 @@ class PollSerializer<T : Poll>(valueSerializer: KSerializer<T>) : KSerializer<Po
),
arrayOf(
LanguageDependencePoll.serializer(),
PlayerAgePoll.serializer(valueSerializer),
PlayerAgePoll.serializer(),
NumberOfPlayersPoll.serializer(),
),
)
Expand Down
6 changes: 2 additions & 4 deletions src/main/kotlin/org/audux/bgg/response/Things.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import com.fasterxml.jackson.annotation.JsonTypeInfo
import com.fasterxml.jackson.databind.annotation.JsonDeserialize
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty
import kotlinx.serialization.Polymorphic
import java.net.URI
import java.time.LocalDate
import java.time.LocalDateTime
Expand Down Expand Up @@ -148,7 +147,7 @@ data class Thing(
@JsonIgnore var name: String = "",

/** Contains a list of polls such as the [PlayerAgePoll]. */
@Polymorphic var polls: List<Poll> = listOf(),
var polls: List<Poll> = listOf(),

/**
* Depending on the [type] this list may contain different links e.g. for boardgames links such
Expand Down Expand Up @@ -367,8 +366,7 @@ data class Price(
@Serializable
data class Weblink(
/** Link to web resource. */
@Serializable(with = URISerializer::class)
val href: URI,
@Serializable(with = URISerializer::class) val href: URI,

/** The title of the resource. */
val title: String,
Expand Down
12 changes: 9 additions & 3 deletions src/test/kotlin/org/audux/bgg/response/ThingsResponseTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ package org.audux.bgg.response

import com.fasterxml.jackson.databind.ObjectMapper
import com.google.common.truth.Truth.assertThat
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import java.net.URI
import java.time.LocalDate
import java.time.LocalDateTime
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import org.audux.bgg.common.ThingType
import org.audux.bgg.util.TestUtils
import org.junit.jupiter.api.Nested
Expand All @@ -45,7 +45,13 @@ class ThingsResponseTest {

@Test
fun `is (K)Serializable`() {
val things = mapper.readValue(TestUtils.xml("thing?id=1"), Things::class.java)
val things =
mapper.readValue(
TestUtils.xml(
"thing?id=396790&stats=1&ratingcomments=1&versions=1&marketplace=1&videos=1"
),
Things::class.java
)
val thing = things.things[0]
val encodedThing = Json.encodeToString(thing)

Expand Down

0 comments on commit bde59f7

Please sign in to comment.