Reputation: 191
I'm new in Kotlin language and I try a simple RESTFUL API with Kotlin and Spring Boot. My query methods are not returning the expected result. I was hoping to receive this upon return of the requisition:
[
{
"id": 0,
"name": "string 1",
"color": "string 1"
},
{
"id": 1,
"name": "string 2",
"color": "string 2"
}
]
But I receive this (HTTP status 200):
[
{},
{}
]
My data base have categories and my service and repository perform OK.This is the code of my controller:
@RestController
@RequestMapping("/category")
class CategoryController (val categoryService: CategoryService) {
@GetMapping
fun findAll(): ResponseEntity<Any> {
try {
return ResponseEntity.ok(categoryService.findAll())
} catch (e: Exception) {
val msg = "Something went wrong: " + e.message
return ResponseEntity(msg, HttpStatus.INTERNAL_SERVER_ERROR)
}
}
}
What I'm doing wrong? I thank you for your help!
Upvotes: 5
Views: 3157
Reputation: 191
I found the problem. My data class variables was private, i remove the private declaration and now the content is showed at the response body
Upvotes: 13