SerializeJSON returning stringified JSON object

OS : Windows
Java Version : 11.0.15
Tomcat Version : 9.0.45
Lucee Version : 5.3.9.141

I am currently trying to migrate over our application from ACF to Lucee, we have multiple rest services returning json objects.

When we first switched to lucee it was clear that the rest services were now being stringified to something resembling "{\"MESSAGE\":\"Cabbages\",\"STATUS\":201}"

This is not what we want as we need to be returning json objects

Using the tutorial on this page: SerializeJSON() :: Lucee Documentation

I did this test, which shows that if I serializeJSON once I should get the output I want:

My code currently looks like this and outputs the stringified version. Why does this happen?

<cfcomponent rest="true" restPath="/refresh" produces="application/json">
		<cffunction restPath="/5" name="networkPapers" access="remote" returnType="any" httpMethod="GET">

            <cfscript>

                json3 = {"MESSAGE":"Cabbages","STATUS":201}
                return serializeJSON(json3)
            </cfscript>
        </cffunction>
</cfcomponent>

I have never used Lucee’s rest services.

But it seems clear to me that someone serializes your data twice.

Try modify this:
return serializeJSON(json3);

to:
return json3;

what happens?

I thought this
produces = "application / json"
can implicitly produce a Json

Hi @Roberto_Marzialetti ,

I agree it seems that serialization seems to be happening twice, however in ACF it doesn’t happen twice and I would like to keep the same code functional on both platforms for now, is there a way I can alter the method to not default to serialize twice?

without modify the body of function, try:
produces="text/plain"

as the same code I don’t think it’s possible …

Can you point us at the docs for ColdFusion that say you need to do the JSON serialisation yourself in these situations? I didn’t think you had to, but I’ve not touched this stuff in close to a decade. I seemed to recall that one just returned the object from the function, and the CFML REST engine handles the serialisation if you have told it to return JSON or XML…?

If there is a behavioural difference between CF and Lucee here, a compat ticket should be raised in Lucee’s Jira, yeah?