Unable to switch between xml and json with rest service
Hi there,
I recently built a ColdFusion 2021 server and I am trying to run "legacy code" on it.
I have a service called getBank which I could call from the browser with https://***/rest/services/getBanl.xml or /getBank.json with ColdFusion 11 which would return a response in the correct format. I am now unable to use getBank.json with the new version of ColdFusion. Please assist. See the service below:
<cfcomponent rest="true" restpath="getBanks">
<cfset datasource = "dsn">
<cffunction name="list_type_function" returntype="query">
<cfquery name="resultQuery" datasource="#datasource#">
SELECT bank_id, bank_code, bank_name
FROM banks
</cfquery>
<cfreturn resultQuery>
</cffunction>
<!--- application/json for content negotiation --->
<cffunction access="remote" name="getBanksJSON" output="false" httpmethod="GET" returntype="query" produces="application/json">
<cfset resultQuery = list_type_function()>
<cfreturn resultQuery>
</cffunction>
<!--- application/xml for content negotiation --->
<cffunction access="remote" name="getBanksXML" output="false" httpmethod="GET" returnFormat="plain" returntype="xml" produces="application/xml">
<cfset resultQuery = list_type_function()>
<!--- List of list types based on specified type code --->
<cfxml variable="XMLEval">
<banks>
<cfoutput query="resultQuery">
<cfset request.bank_code = Replace(bank_code,"&","&","ALL")>
<cfset request.bank_name = Replace(bank_name,"&","&","ALL")>
<banks_detail>
<banks_id>#bank_id#</banks_id>
<bank_code>#Trim(request.bank_code)#</bank_code>
<bank_name>#Trim(request.bank_name)#</bank_name>
</banks_detail>
</cfoutput>
</banks>
</cfxml>
<cfset XMLString = toString(XMLEval)>
<cfreturn XMLEval>
</cffunction>
</cfcomponent>
