You would need to provide more details in your question, but I would try to make an reasonable assumptions and provide you with my best guess answer. First of all, why is in your code
Publisher<employee> employeeRows = employeeService.list();
you invoke method called list()
but it returns an instance of a class Publisher<employee>
and not a list. Also if you try to serialize any instance of a class that is not a list into Json you will get a Json object (equivalent of a Map<String, Object>
and not List<Map<String, Object>>
). So, if you want to get a JSON list (equivalent of List<Map<String, Object>>
) you have to have a List<Employee>
. To do so is a strait forward task. You can use ObjectMapper
class for it. But also I wrote am Open-source library that has a class JsonUtils
which is a simple wrapper over ObjectMapper
class that may simplify this task for you. Assuming you have a List<Employee>
your code would look like this:
try {
String jsonListString = writeObjectToJsonString(myEmployeeList);
} catch(JsonProcessingException jpe) {
...
}
Here is a Javadoc for JsonUtils class. The library called MgntUtils and you can get it as maven artifact or on Github (including source code and Javadoc)