Is Lucee capable of returning a valid UTF-8 JSON object?

172 views
Skip to first unread message

Christoph Bühler

unread,
Sep 7, 2015, 3:00:02 AM9/7/15
to Lucee
I have a CFC, which returns a struct, converted into JSON format. This is the method declaration:
<CFFUNCTION name="getJSON" returntype="Struct" returnformat="JSON" output="no" access="remote">

The output looks just fine, but it's not in UTF-8.

I have tried this:

<CFCONTENT type="application/json; charset=utf-8"> <CFPROCESSINGDIRECTIVE pageEncoding="utf-8"> <CFSCRIPT> SetEncoding("url", "utf-8"); SetEncoding("form", "utf-8"); </CFSCRIPT>

And I saved the .cfc file as UTF-8 with BOM.

I want to use this as the datasource for a Jasper report, but I always get this error message:

Invalid UTF-8 middle byte 0x74 at [Source: java.io.ByteArrayInputStream@6c2071a7; line: 1, column: 745]

The JSON data contains german umlauts. First one of them is at this position: "line: 1, column: 745".

The error occurs when creating the datasource. InputStream is not in UTF-8.

jsonUrl = getParam('JSON_URL', ReportParamArray); inputStream = CreateObject("java", "java.net.URL").init(jsonUrl).openConnection().getInputStream(); jasperPrint = jasFillManager.fillReport(jasReport, parameters, CreateObject("java", "net.sf.jasperreports.engine.data.JsonDataSource").init(inputStream));

How can I ensure, that the CFC returns valid UTF-8 content?
Reply all
Reply to author
Forward
0 new messages