ColdFusion, CFHTTP, and java.io.ByteArrayOutputStream

I believe I may have blogged this before, but a reader ran into this yesterday so I thought it might be worth sharing. If you are using CFHTTP to hit a remote and seeing java.io.ByteArrayOutputStream in the result, there is a simple solution around that.

Here is a sample cfdump of just such a response. You are expecting a string of some sort in fileContent, but instead end up with a Java object:

unnamed

To work with this result as a string, you simply need to run toString() on the value. So for example, if you know the response is JSON:

deserializeJSON(result.filecontent.toString())

I’ll be honest and say I don’t know why some servers return that, or why cfhttp can’t simply toString it itself. I’m assuming there is a good reason that probably involves all kind of crap I really don’t care about. ;)

p.s. It looks like this might be just ColdFusion 9 and earlier - see this bug report. I can say it has been a while since I’ve seen it. I’ve run ColdFusion 10 since it came out pretty much.

Raymond Camden's Picture

About Raymond Camden

Raymond is a developer advocate for Extend by Auth0. He focuses on serverless and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support.

Lafayette, LA https://www.raymondcamden.com

Comments