How can I turn my controllers in omod to return json/xml

I want my controllers in the omod to return json, how can I best do it.

You could take a look at these examples: https://github.com/openmrs/openmrs-module-appframework/blob/230081bd2875e14bb936b9d86c1227118caebeea/omod/src/main/java/org/openmrs/module/appframework/web/AppFrameworkController.java

And: https://github.com/openmrs/openmrs-module-appui/blob/0874646d0a1ef9fb0fb2517058543ee65901fae1/omod/src/main/java/org/openmrs/module/appui/rest/SessionController.java

Thank you @dkayiwa But when i try to access the url, it gives me this error

A user context must first be passed to setUserContext()…use Context.openSession() (and closeSession() to prevent memory leaks!) I have tried open the session by using Context.openSession(), but still throws me the same error