28783, "jabraham17", "[Bug]: jsonSerializer used on custom serialized class can result in invalid json", "2026-05-06T23:47:10Z"
Summary of Problem
Description:
I found that with a custom serializer, the jsonSerializer can generate invalid json strings because it tries to escape strings too early
Is this issue currently blocking your progress?
no
Steps to Reproduce
Source Code:
use Map;
record myRec: writeSerializable {
var x: int;
}
proc myRec.serialize(writer, ref serializer) throws {
writer.write("x is \"", x, "\"");
}
var m: map(string, myRec);
m.add("first", new myRec(x=1));
m.add("second", new myRec(x=2));
use IO, JSON;
stdout.withSerializer(new jsonSerializer()).writeln(m);
Output
{
"second": "x is \""2"\"",
"first": "x is \""1"\""
}
Expected output
{
"second": "x is \"2\"",
"first": "x is \"1\""
}
if writer.write("x is \"", x, "\""); is written instead as writer.write("x is \"" + x:string + "\"");, everything works fine