How to convert or cast hashmap to JSON object in Java, and again convert JSON object to JSON string?
This is typically the work of a Json library, you should not try to do it yourself. All json libraries should implement what you are asking for, and you can find a list of Java Json libraries on json.org, at the bottom of the page.