Kotlin暴露了多对多Jackson无限递归(StackOverflowError)

时间:2019-04-04 14:02:28

标签: kotlin-exposed

我在ExposedBD(kotlin)中进行了多对多引用,如下所示: https://github.com/JetBrains/Exposed/wiki/DAO#many-to-many-reference

但是,当我尝试在我的API(Javalin)中返回对象列表时,存在无限递归(Jackson)的问题。 因此,我想知道如何添加注释“ @jsonIgnore”,或者在这种情况下是否还有其他替代解决方案。这是映射:

非常感谢

// many-to-many Actor--StarWarsFilms

// Actor Entity
object Actors: IntIdTable() {
    val firstname = varchar("firstname", 50)
    val lastname = varchar("lastname", 50)
}

class Actor(id: EntityID<Int>): IntEntity(id) {
    companion object : IntEntityClass<Actor>(Actors)

    var firstname by Actors.firstname
    var lastname by Actors.lastname
}

// StarWarFilm Entity
object StarWarsFilms : IntIdTable() {
  val sequelId = integer("sequel_id").uniqueIndex()
  val name = varchar("name", 50)
  val director = varchar("director", 50)
}

class StarWarsFilm(id: EntityID<Int>) : IntEntity(id) {
 companion object : IntEntityClass<StarWarsFilm>(StarWarsFilms)

 var sequelId by StarWarsFilms.sequelId 
 var name     by StarWarsFilms.name
 var director by StarWarsFilms.director
 var actors by Actor via StarWarsFilmActors
}

// Intermediate table
object StarWarsFilmActors : Table() {
    val starWarsFilm = reference("starWarsFilm", StarWarsFilms).primaryKey(0)
    val actor = reference("actor", Actors).primaryKey(1)
}

0 个答案:

没有答案