In Spring Boot, primitive types (like Boolean or Integer) are serialized directly as a pure value in the response body, without being wrapped in an object (so you get true
and false
).
Make a class in your kotlin code
data class BooleanResponse(val value: Boolean)
then, dear @padmalcom, you can write something like
@GetMapping("/api/v1/user/existsByUsername/{username}", produces = [MediaType.APPLICATION_JSON_VALUE])
@ResponseBody
fun userExistsByUsername(@PathVariable("username") username: String): ResponseEntity<BooleanResponse> {
val exists = userService.usernameExists(username)
return ResponseEntity.status(HttpStatus.OK).body(BooleanResponse(exists))
}
that uses your class.
So your JSON return will be:
{
"value": true
}
with curly braces.
Fast & ̶f̶u̶r̶i̶o̶u̶s̶ simple