I want to return a simple json result, something like:
{ 12323: true }
Or if I can’t have a boolean value, then 1 or 0.
My spring controller is like:
@ReqeustMapping("/getResultFor")
@ResponseBody
public String getResultForXXXX(HttpServletRequest request, ...) {
userId = 123;
bool isSaved = true;
// ????????? create object and convert to json
//
return someJson;
}
So I have my userId and bool variable, I need to wrap in in a structure and convert that to json. I don’t want to create a new class/type for this structure (preferrably).
We’ve been using Jackson for quite sometime. https://github.com/FasterXML/jackson and been very pleased with it. You would create a Java POJO with your fields and have Jackson serialize it to JSON.