Spring Boot include ID field in json Spring Boot include ID field in json json json

Spring Boot include ID field in json


By declaring a member property private you're telling Kotlin not to generate a getter for it.
Jackson, which is used by SpringBoot, uses getters to serialize objects.
That's the reason it doesn't see your property. And if it doesn't see the property, it doesn't get annotation either.
Easiest way to solve it would be to leave it as a val, but make it not private: val sideNumber: Int

More complicated way would be to create a @Bean of type ObjectMapper and configure Jackson to serialize also private members, as described here: https://docs.spring.io/spring-boot/docs/current/reference/html/howto-spring-mvc.html#howto-customize-the-jackson-objectmapper