Could not write JSON: No serializer found for class org.json.JSONObject and no properties discovered to create BeanSerializer

This will throw an error, as JSONObject does not expose default getter. Although a workaround can be done to avoid this thing.

You need to change ResponseGenerator class to accept Map<String, Object> instead of JSONObject. Now change this line:

responseGenerator.setJSONData(data);

to this:

 responseGenerator.setJSONData(data.toMap());

I hope this should work.

P.S.: My recommendation would be to remove JSONObject conversion and instead return an Object of actual class,as internally spring uses jackson, which is more powerful JSON framework then org.json

Tags:

Java

Json

Spring