There is a Spring Rest Controller :
@RestController
@RequestMapping("secanalytique")
public class SectionAnalytiqueController {
@GetMapping(value = "/sectionbyaxepro/{codecomp}", produces = "application/json")
public JSONObject getByAxePro(@PathVariable String codecomp) {
JSONObject jsonModel = new JSONObject();
jsonModel.put("cce0","frityyy");
return jsonModel;
}
}
I made a test with Postman : http://172.20.40.4:8080/Oxalys_WS/secanalytique/sectionbyaxepro/8 ; and what I got is always
{
"empty": false
}
So what is wrong ?
There was one issue with your implementation that you are creating json object explicitly and returning it which is not required.
Instead, you should just send your java POJO/class, spring will convert it to JSON and return it.
Spring uses Jackson as the default serializer/deserializer. Here since an object is already JSONObject, Jackson does not know how to serialize it.
There are two way to solve this
1. Define your own data type and populate it.
1
2
Instead of creating JSONObject manually you can handle it in this way