Hi Omer,
You can create a json structure an export mapping for this structure and then utilize the export mapping activity to generate your json string. If you have a list, for the export mapping to work, I believe you will need to associate that list to a single object with a many to 1 relationship.
Here is some documentation on export mappings.
https://docs.mendix.com/refguide/export-mappings
Hope this helps!
Just thinking out aloud here. In your Java you have the list of MxObjects. Could you not use the Jackson library to convert the Mendix object to a JSON object ( https://blog.codota.com/how-to-convert-a-java-object-into-a-json-string/ ) based on the model reflection? Because from each Mendix object you have the attribute name and type and thus create a generic JSON object according through this.
Another sollutions would be that based on the entity you know what list the Java action returns and based on that call another microflow that does the mapping. But this would only work if the number of entities is not that big.
Regards,
Ronald