Custom serializer help

46 views
Skip to first unread message

Jonathan Brookins

unread,
Mar 10, 2016, 4:20:38 PM3/10/16
to Taffy Users
I'm trying to upgrade our Lucee project with the latest (3.1) Taffy code.  Most of it seems to work, but for some reason the custom serializer I am using seems to be ignoring the default.  Rather than defaulting to json it is defaulting to xml.  Here is the serializer code I am using
component extends="taffy.core.baseSerializer" output="false" {
 
function getAsJson() taffy_mime = "application/json;text/json" taffy_default = "true" {
 
return serializeJSON(variables.data);
 
}


 
function getAsXML() taffy_mime = "application/xml" taffy_default = "false" {
 
return application.AnythingToXML.toXml(variables.data);
 
}
}

Everything works fine if you append .json or .xml, it is just defaulting to xml for some reason.  Any ideas?

Adam Tuttle

unread,
Mar 10, 2016, 4:48:59 PM3/10/16
to Taffy Users
How are you testing it? Browsers -- and maybe even XHR (?) -- will set the Accept header to include application/xml by default. However you're testing, inspect the network request. I suspect that you're sending a header that you're not intending.

Adam

--
You received this message because you are subscribed to the Google Groups "Taffy Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to taffy-users...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jonathan Brookins

unread,
Mar 10, 2016, 5:33:20 PM3/10/16
to Taffy Users
Thanks, Adam.  Was unaware about the browser sending the application/xml content type by default.  The weird thing is that when I use curl to test it returns a zero content length.  Not sure what is going on, but at least using curl it returns the json content type as the default, so I suppose the serializer is working fine.  Strange that it isn't returning any content, though. It does in the browser and using the api dashboard.  I'll keep investigating, thanks again for the timely help!

Jonathan Brookins

unread,
Mar 10, 2016, 5:51:12 PM3/10/16
to Taffy Users
I'm such an idiot.  The reason curl isn't giving me what I wanted is that the response is gzipped.  Adding the header to curl and I get the response I was expecting.  Ugh.
Reply all
Reply to author
Forward
0 new messages