79337750

Date: 2025-01-08 01:19:09
Score: 1
Natty:
Report link

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

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • User mentioned (1): @padmalcom
  • Low reputation (1):
Posted by: PHPKiatofiaFlowOverUs