Serializing a list back to the REST caller?

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}"
    }

FWIW, the latest attempt is to call toSpreadMap on it, however I get that it’s unable to do so because the size is “uneven”.

return commands.toSpreadMap()