renderData and CF's serializeJSON conflict

I came across a situation today that I thought I would share. I’m not sure if it’s something that is best addressed within the framework via modifications or best addressed by the developer in how they write their code, but here is the scenario for consideration:

I have an event that places a query of users into the requestcontext. My template grabs that query and serializes it to JSON for use within some Javascript functions, similar to the following:

//make our initial data sets available to JS... var objUsers = #serializeJSON(qryUsers,true)#; This template allows the modification, addition, and deletion of users to the system via Ajax calls. One of these calls returns another complete copy of the user query in JSON format, to replace the Javascript object I created initially using the serializeJSON tag. objUsers = AjaxReponse; The Ajax call I refer to is returning data via the event.renderData method, relying on the built in data marshalling by specifying the return type as JSON and providing the user query as the data attribute. Here is the challenge: The data marshalling functionality does not utilize CF's serializeJSON function for queries, and so the format of the JSON returned by the data marshalling is different than that produced by CF's serializeJSON with the optional 'true' attribute. In my mind, I expected that if I provided a CF query and specified JSON as the format, I would get the same results as if I had used serializeJSON. The solution I had to go with was to change the type to "plain" and perform the serializeJSON inline within the renderData call. I suppose perhaps I could have used the JSON plugin Coldbox provides in lieu of serializeJSON...but I wasn't even aware of its existence until today. :) So, do you think this is an issue that needs to be addressed internally to the framework? If not, at the very least it may be a valuable piece of information to include in the documentation, warning developers NOT to expect the same results as with the serializeJSON function. Doug :0)

Hi Doug,

Unfortunately, the json plugin will remain in existence until cf7 is depreacted in order to support cf7 platform. Once cf7 is deprecated by Adobe, we will remove the plugin and rely on the cf engine’s serialize and deserialze JSON methods. I would suggest using one or the other but not both in combination.

Luis