I have a code from a REST API which uses @ResponseBody
to return the result, and a MappingJacksonHttpMessageConverter
to return it in a JSON format.
It all works well for complex objects.
For primitives like int
, boolean
and string
I get a JSON which does not start with { or [.
This is not a valid JSON.
I was wondering what is the proper way to return just a simple type like that?
Should I encapsulate it in an object such as { Result : true }
?
Thanks
Code sample:
@RequestMapping(
value = "/login",
method = RequestMethod.POST)
@ResponseBody
public boolean Login(String username, String password) {
return authenticationService.authenticate(username, password);
}
This will return just true
or false
which is an invalid JSON. It should either be encapsulated in an object or an array (if I understand correctly).