Version: 1.0-a8 JDK 17.
Text.renderCharSequence puts the CharSequence object itself into the DisplayData bundle for every requested mime type:
context.renderIfRequested(PLAIN, () -> data); // raw object, not data.toString()
Since the kernel returns real result objects (via the takeResult mechanism), the stored object is later serialized by Gson when the execute_result message is sent — and Gson only produces sensible output for types it has adapters for. Observed results for a cell whose value is a CharSequence:
| Result value |
What the frontend receives |
String, StringBuilder, StringBuffer |
correct text (Gson happens to ship adapters) |
java.nio.CharBuffer.wrap("hello") |
JsonIOException: Failed making field 'java.nio.StringCharBuffer#str' accessible… during message serialization |
any library/user CharSequence (e.g. commons-text TextStringBuilder) |
reflective field dump, e.g. {"s":"hello"} |
Groovy GString (via a jjava-jupyter-based Groovy kernel) |
{"strings":[…], "values":[…], "frozen":false, …} |
Standalone repro (no notebook needed):
Renderer renderer = new Renderer();
Text.registerAll(renderer);
Object stored = renderer.render(java.nio.CharBuffer.wrap("hello")).getData(MIMEType.TEXT_PLAIN);
new com.google.gson.Gson().toJson(stored); // JsonIOException; a custom CharSequence yields {"s":"hello"}
Suggested fix: materialize the text at render time — renderIfRequested(PLAIN, () -> String.valueOf(data)) (likewise for the other supported mimes in renderCharSequence). Happy to send a PR.
Context: found while building groovy-jupyter, a Groovy kernel on top of the jjava-jupyter base module (where every GString result hits this).
Version: 1.0-a8 JDK 17.
Text.renderCharSequenceputs theCharSequenceobject itself into theDisplayDatabundle for every requested mime type:Since the kernel returns real result objects (via the
takeResultmechanism), the stored object is later serialized by Gson when theexecute_resultmessage is sent — and Gson only produces sensible output for types it has adapters for. Observed results for a cell whose value is aCharSequence:String,StringBuilder,StringBufferjava.nio.CharBuffer.wrap("hello")JsonIOException: Failed making field 'java.nio.StringCharBuffer#str' accessible…during message serializationCharSequence(e.g. commons-textTextStringBuilder){"s":"hello"}GString(via a jjava-jupyter-based Groovy kernel){"strings":[…], "values":[…], "frozen":false, …}Standalone repro (no notebook needed):
Suggested fix: materialize the text at render time —
renderIfRequested(PLAIN, () -> String.valueOf(data))(likewise for the other supported mimes inrenderCharSequence). Happy to send a PR.Context: found while building groovy-jupyter, a Groovy kernel on top of the
jjava-jupyterbase module (where everyGStringresult hits this).