diff --git a/protocol/src/commonMain/kotlin/dev/arbjerg/lavalink/protocol/v4/loadResult.kt b/protocol/src/commonMain/kotlin/dev/arbjerg/lavalink/protocol/v4/loadResult.kt index 95e631e9b..a996e5ab4 100644 --- a/protocol/src/commonMain/kotlin/dev/arbjerg/lavalink/protocol/v4/loadResult.kt +++ b/protocol/src/commonMain/kotlin/dev/arbjerg/lavalink/protocol/v4/loadResult.kt @@ -96,7 +96,7 @@ sealed interface LoadResult { companion object { fun trackLoaded(track: Track) = TrackLoaded(track) - fun playlistLoaded(playlistInfo: PlaylistInfo, pluginInfo: PluginData, tracks: List) = + fun playlistLoaded(playlistInfo: PlaylistInfo, pluginInfo: JsonObject, tracks: List) = PlaylistLoaded( Playlist( playlistInfo, @@ -133,9 +133,11 @@ data class PlaylistInfo( @Serializable data class Playlist( val info: PlaylistInfo, - val pluginInfo: PluginData, + val pluginInfo: JsonObject, val tracks: List -) : LoadResult.Data +) : LoadResult.Data { + fun deserialize(deserializer: DeserializationStrategy): T = pluginInfo.deserialize(deserializer) +} @Serializable data class Exception( diff --git a/protocol/src/commonMain/kotlin/dev/arbjerg/lavalink/protocol/v4/player.kt b/protocol/src/commonMain/kotlin/dev/arbjerg/lavalink/protocol/v4/player.kt index b3f237871..95bfdc4ef 100644 --- a/protocol/src/commonMain/kotlin/dev/arbjerg/lavalink/protocol/v4/player.kt +++ b/protocol/src/commonMain/kotlin/dev/arbjerg/lavalink/protocol/v4/player.kt @@ -6,12 +6,11 @@ import kotlinx.serialization.json.JsonObject import kotlinx.serialization.serializer import kotlin.jvm.JvmInline -@Serializable -@JvmInline -value class PluginData(private val obj: JsonObject){ - inline fun deserialize(): T = deserialize(json.serializersModule.serializer()) - fun deserialize(deserializer: DeserializationStrategy): T = json.decodeFromJsonElement(deserializer, obj) -} +inline fun JsonObject.deserialize(): T = + deserialize(json.serializersModule.serializer()) + +fun JsonObject.deserialize(deserializer: DeserializationStrategy): T = + json.decodeFromJsonElement(deserializer, this) @Serializable @JvmInline @@ -32,8 +31,10 @@ data class Player( data class Track( val encoded: String, val info: TrackInfo, - val pluginInfo: PluginData -) : LoadResult.Data + val pluginInfo: JsonObject +) : LoadResult.Data { + fun deserialize(deserializer: DeserializationStrategy): T = pluginInfo.deserialize(deserializer) +} @Serializable @JvmInline diff --git a/protocol/src/commonTest/kotlin/LoadResultSerializerTest.kt b/protocol/src/commonTest/kotlin/LoadResultSerializerTest.kt index f4dbe29ca..01842c3dc 100644 --- a/protocol/src/commonTest/kotlin/LoadResultSerializerTest.kt +++ b/protocol/src/commonTest/kotlin/LoadResultSerializerTest.kt @@ -151,7 +151,7 @@ class LoadResultSerializerTest { loadType shouldBe ResultStatus.PLAYLIST assertIs(this) data { - pluginInfo shouldBe JsonObject(emptyMap()) + pluginInfo shouldBe emptyMap() info { name shouldBe "Example YouTube Playlist" selectedTrack shouldBe 3