Я использую весеннюю загрузку с 2.0.0.M6 с kotlin 1.1.51 с org.springframework.boot:spring-boot-starter-data-rest и пытаюсь отформатировать вывод json.
Как я могу настроить. spring rest data, чтобы он выводил / принимал внешний ключ вместо объекта с href в ManyToOne-Relationship?
образец модели с внешним ключом language_id (котлин):
@Entity
data class Song (
@Column
var title: String,
@Column
var songTypeId: Int,
@OneToMany(mappedBy = "song")
var mastersheets: Set<Mastersheet> = setOf<Mastersheet>()
) : UpdateableBaseEntity() {
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "language_id", nullable = false)
lateinit var language: Language
@ManyToOne()
@JoinColumn(name = "artist_id", nullable = false)
lateinit var artist: Artist
}
вывод выглядит примерно так:
{
"_embedded" : {
"songs" : [ {
"title" : "Hello World",
"songTypeId" : 1,
"insertDate" : "2018-09-06T07:25:14.307+0000",
"updateDate" : null,
"_links" : {
"self" : {
"href" : "http://localhost/songs/1"
},
"song" : {
"href" : "http://localhost/songs/1"
},
"artist" : {
"href" : "http://localhost/songs/1/artist"
},
"mastersheets" : {
"href" : "http://localhost/songs/1/mastersheets"
},
"language" : {
"href" : "http://localhost/songs/1/language"
}
}
} ]
},
"_links" : {
"self" : {
"href" : "http://localhost/songs"
},
"profile" : {
"href" : "http://localhost/profile/songs"
}
}
}
Примечание: я также пробовал эту конфигурацию
@Bean
fun repositoryRestConfigurer(): RepositoryRestConfigurer {
return object : RepositoryRestConfigurerAdapter() {
override fun configureRepositoryRestConfiguration(config: RepositoryRestConfiguration?) {
config!!.exposeIdsFor(Language::class.java)
}
}
}

Я нашел свое решение здесь https://stackoverflow.com/a/38165158/2248405
С помощью SpringExpression Language (SpEL) можно разместить все в одном объекте:
@Projection(name = "fullDetails", types = arrayOf(Song::class))
interface SongsFullDetailsProjection {
fun getId(): Long
fun getTitle(): String
@Value("#{target.getArtist()?.getId()}")
fun getArtistId(): Long?
@Value("#{target.getSongType()?.getId()}")
fun getSongTypeId(): Long?
@Value("#{target.getLanguage()?.getId()}")
fun getLanguageId(): Long?
}