Issue
When I run my program and open localhost:8080, I get all this on one line:
{"friends":{"bob":{"name":"bob","age":1},"bobby":{"name":"bobby","age":-4}}}
How do I make it have indents like a json object?
{
"friends": {
"bob": {
"name": "bob",
"age":1
},
"bobby": {
"name": "bobby",
"age": -4
}
}
}
my code is this:
@RestController
@RequestMapping("/")
public class FriendResource {
@GetMapping
public @ResponseBody ResponseEntity<Dude> getDude() {
return new ResponseEntity<>(new Dude())), HttpStatus.OK);
}
}
Solution
By default, Spring Boot uses Jackson when turning objects into json. To get output in the form that you want, enable its indent output feature. To do so, add the following to your application.properties
file in your project’s src/main/resources
directory:
spring.jackson.serialization.indent-output=true
Answered By - Andy Wilkinson