Kotlin Notebook deserializeJson with invalid class schema
已完成
Here is the code block i use in kotlin notebook and one of the definition of the data classes is wrong;
%trackExecution
%use ktor-client, dataframe
val response = http.get("<i cant specify the url>")
val deserializeJson = response.deserializeJson()
The result contains many data classes but one of the is defined as;
@Serializable
data class (
@SerialName("id")
val id: String,
// other fields
)
As it can be seen, class name is not there. The other data classes looks pretty good. Am i missing something?
请先登录再写评论。
Hi! It may be somewhat hard to reproduce this error without a JSON fragment. Is there a chance you can provide one? No actual data is required, just the field names of the JSON.
Thank you.
Okay, i have reproduced the issue for another url. here is the full code that has the problem also;
%trackExecution
%use ktor-client, dataframe
import io.ktor.client.request.headers
import io.ktor.http.HttpHeaders
import io.ktor.http.append
val response = http.get("https://api.gainapis.com/v2/content/playlist/category?playlistLimit=100&videoLimit=100&cw=false&categoryId=pFlIW25nHIeRkjjIBLLg&lastPlaylistIndex=0") {
headers {
append("x-app-language", "TR")
}
}
val deserializeJson = response.deserializeJson()
the output;
Executing:
val deserializeJson = response.deserializeJson()
Executing:
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
@Serializable
data class DeserializeJson(
@SerialName("data")
val `data`: Data,
@SerialName("error")
val error: Error
)
@Serializable
data class Data(
@SerialName("playlists")
val playlists: List<Playlists>,
@SerialName("isLastPage")
val isLastPage: Boolean,
@SerialName("lastPlaylistIndex")
val lastPlaylistIndex: Int,
@SerialName("totalCount")
val totalCount: Int
)
@Serializable
class Error
@Serializable
data class Playlists(
@SerialName("list")
val list: List<>,
@SerialName("lastPage")
val lastPage: Boolean,
@SerialName("lastIndex")
val lastIndex: Int,
@SerialName("totalCount")
val totalCount: Int,
@SerialName("name")
val name: String,
@SerialName("type")
val type: String,
@SerialName("playlistId")
val playlistId: String,
@SerialName("playlistType")
val playlistType: String
)
@Serializable
data class (
@SerialName("id")
val id: String,
@SerialName("metadata")
val metadata: Metadata,
@SerialName("episodeNumber")
val episodeNumber: Int?,
@SerialName("seasonNumber")
val seasonNumber: Int?,
@SerialName("seasonCount")
val seasonCount: Int?,
@SerialName("placeholderText")
val placeholderText: UntypedAny?,
@SerialName("type")
val type: String,
@SerialName("continueWatch")
val continueWatch: UntypedAny?,
@SerialName("titleId")
val titleId: String,
@SerialName("mediaId")
val mediaId: String?
)
@Serializable
data class Metadata(
@SerialName("name")
val name: String,
@SerialName("contentRatings")
val contentRatings: List<String>,
@SerialName("description")
val description: String,
@SerialName("duration")
val duration: Int?,
@SerialName("category")
val category: String,
@SerialName("imdbScore")
val imdbScore: String?,
@SerialName("isGainOriginals")
val isGainOriginals: Boolean,
@SerialName("isFree")
val isFree: Boolean,
@SerialName("images")
val images: Images,
@SerialName("tags")
val tags: List<String>
)
@Serializable
data class Images(
@SerialName("thumbnails")
val thumbnails: List<Thumbnail>,
@SerialName("coverPhotos")
val coverPhotos: List<CoverPhoto>,
@SerialName("logos")
val logos: List<Logo>?
)
@Serializable
data class Thumbnail(
@SerialName("url")
val url: String,
@SerialName("orientation")
val orientation: String,
@SerialName("width")
val width: Int,
@SerialName("type")
val type: String
)
@Serializable
data class CoverPhoto(
@SerialName("url")
val url: String,
@SerialName("orientation")
val orientation: String,
@SerialName("width")
val width: Int,
@SerialName("type")
val type: String
)
@Serializable
data class Logo(
@SerialName("url")
val url: String,
@SerialName("orientation")
val orientation: String,
@SerialName("width")
val width: Int,
@SerialName("type")
val type: String
)
Thank you for reporting this. I have reproduced the problem and created an issue on YouTrack: https://youtrack.jetbrains.com/issue/KTNB-733/JSON-serialization-integration-empty-class-name-generated. We will probably fix it within the next two weeks.
@... has there any update on this??
Fernandoobregon sorry for the lack of updates. Yes, this issue has been fixed. You need to start the code with
%useLatestDescriptors
in order for the latest version (which contains the fix) of serialization utils to be used.