Manasseh
07/30/2023, 7:03 AMkotlinx.serialization.SerializationException: Class 'LinkedHashMap' is not registered for polymorphic serialization in the scope of 'Map'. Mark the base class as 'sealed' or register the serializer explicitly.
I'd appreciate any help on how to fix this.Aleksei Tirman [JB]
07/30/2023, 8:26 AMUserSerializer
class?Manasseh
07/30/2023, 9:55 AM@Serializable
data class UserSerializer(
val email: String,
val handle: String,
val password: String,
val dateCreated: String,
val dateModified: String
)
Route handler (not sure if this what you mean):
fun Application.configureRouting() {
routing {
static("/static") {
resources("static")
}
get("") {
call.respondFile(File("src/main/resources/openapi/swagger/index.html"))
}
get("/documentation.yaml") {
call.respondFile(File("src/main/resources/openapi/documentation.yaml"))
}
authRouting()
adminRouting()
userRouting()
}
}
Aleksei Tirman [JB]
07/30/2023, 10:22 AMfun main() {
Database.connect("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1", driver = "org.h2.Driver")
transaction {
addLogger(StdOutSqlLogger)
SchemaUtils.create(Users)
Users.insert {
it[name] = "test"
}
}
embeddedServer(Netty, port = 7080) {
install(ContentNegotiation) {
json()
}
routing {
get {
val users = transaction {
val res = Users.selectAll()
res.map {
UserSerializer(it[Users.name])
}
}
call.respond(status = HttpStatusCode.Accepted, mapOf("data" to users))
}
}
}.start(wait = true)
}
object Users : IntIdTable()
{
val name = varchar("name", 100)
}
@Serializable
data class UserSerializer(
val email: String,
)
Manasseh
07/30/2023, 10:24 AMAleksei Tirman [JB]
07/30/2023, 10:26 AMManasseh
07/30/2023, 10:37 AMManasseh
07/30/2023, 10:37 AMAleksei Tirman [JB]
07/30/2023, 12:02 PMManasseh
07/30/2023, 12:22 PMManasseh
07/30/2023, 12:23 PMAleksei Tirman [JB]
07/30/2023, 1:21 PMManasseh
07/30/2023, 6:22 PMManasseh
07/30/2023, 6:25 PM@Serializable
data class ProfileSerializer(
val name: String,
val bio: String,
val location: String,
val website: String,
val displayPicture: ExposedBlob,
val bannerPicture: ExposedBlob,
val dateOfBirth: String,
@Contextual
val id: EntityID<Int>,
)
My IDE keeps highlighting that and returns the error message: "Serializer has not been found for type 'ExposedBlob'. To use context serializer as fallback, explicitly annotate type or property with @Contextual"Manasseh
07/30/2023, 6:28 PMobject ExposedBlobSerializer : KSerializer<ExposedBlob> {
override fun serialize(encoder: Encoder, value: ExposedBlob) {
encoder.encodeBytes(value.bytes)
}
override val descriptor: SerialDescriptor
get() = TODO("Not yet implemented")
override fun deserialize(decoder: Decoder): ExposedBlob {
val bytes = decoder.decodeBytes()
return ExposedBlob(bytes)
}
}
It keeps raising "Unresolved reference" for the encodeBytes() and decodeBytes() methods.Aleksei Tirman [JB]
07/31/2023, 9:28 AMManasseh
07/31/2023, 11:19 AMManasseh
07/31/2023, 11:20 AMManasseh
07/31/2023, 11:20 AMAleksei Tirman [JB]
07/31/2023, 11:23 AMManasseh
07/31/2023, 11:23 AMAleksei Tirman [JB]
07/31/2023, 11:24 AMAleksei Tirman [JB]
07/31/2023, 11:24 AMManasseh
07/31/2023, 11:32 AMAleksei Tirman [JB]
07/31/2023, 11:32 AMManasseh
07/31/2023, 11:33 AMManasseh
07/31/2023, 11:33 AM