Serializing a list back to the caller (without crashing)

I realize I posted my original request to the wrong forum category. Hopefully someone here has an idea. Thanks!

I know this is a stupid developer trick and I’m just missing something; but I’m trying to enumerate the list of possible commands for a device and serialize them out to the caller. I keep getting errors no matter how I tried to do it. I’ve taken my thirteen different attempts out of the text below - how would you serialize device.supportedCommands back to the caller?

path("/switches/commands/:id/") {
            action: [
                GET: "listSwitchCommands"
            ]
        }
    
def listSwitchCommands() {
    	log.debug "in listSwitchCommands"
    	listCommands(switches)
    }
    
def listCommands (devices) {
      	log.debug "In listCommands"
       
        def device = devices.find { it.id == params.id }
        
        log.debug "found device ${device}"
        def commands = device.supportedCommands
        log.debug "commands list ${device.supportedCommands}"
    }