Exposed
Exposed copied to clipboard
class declares multiple JSON fields named primaryKey
Error:
java.lang.IllegalArgumentException: class run.flake.entities.database.users.UsersTable declares multiple JSON fields named primaryKey
Router:
get {
val server = transaction {
ServerRow.new {
name = serverName
owner = user
members = SizedCollection(user)
}
}
call.respond(transaction { server.toMap() }) // Here is error
}
.toMap():
fun <ID : Comparable<ID>> Entity<ID>.toMap2(): Map<String, Any?> {
return this::class.declaredMemberProperties
.associate {
it.name to it.apply { isAccessible = true }.call(this)
}
}
ServerRow
class ServerRow(id: EntityID<UUID>) : UUIDEntity(id) {
companion object : UUIDEntityClass<ServerRow>(ServersTable)
var name by ServersTable.name
var description by ServersTable.description
var members by UserRow via MembersTable
var owner by UserRow referencedOn ServersTable.owner
val groups by GroupRow referrersOn GroupsTable.server
val roles by RoleRow referrersOn RolesTable.server
var createdAt by ServersTable.createdAt
}
UserRow:
class UserRow(id: EntityID<UUID>) : UUIDEntity(id) {
companion object : UUIDEntityClass<UserRow>(UsersTable)
var lokin by UsersTable.lokin
var password by UsersTable.password
var username by UsersTable.username
var region by UsersTable.locale
var registeredAt by UsersTable.registeredAt
var accessLevel by UsersTable.accessLevel
var isBanned by UsersTable.isBanned
}
@ChA0S-f4me
Is toMap2 function something that you wrote?
@ChA0S-f4me Is
toMap2function something that you wrote?
Sure
@ChA0S-f4me I use the following example code to solve it
fun <ID : Comparable<ID>> Entity<ID>.toMap(): Map<String, Any?> {
val map = this::class.declaredMemberProperties.associate {
it.name to it.apply { isAccessible = true }.call(this)
}.toMutableMap()
map["id"] = id.value;
return map
}
hope that helps to you。
@xiaoliang-cn looks like you are trying to serialize UserTable with gson. Can you show the complete stacktrace to confirm it?
I started using jackson instead of GSON, after that it started working normally