Description
Currently, if you have a GenericData.Record and call toString on it, it provides a JSON representation of this record type. However, if the record contains a string that contains a literal forward slash, the forward slash gets escaped by the writeEscapedString function which means that the string representation is not equivalent after round-tripping the value.
According to the ECMA standard for JSON, forward slash can be escaped; however, the values "\u002F", "\u002f", "\/", and "/" are all the same. Thus, it seems preferable to produce the shortest version. This is the way that Jackson works as well:
JsonMapper mapper = new JsonMapper(); JsonFactory factory = new JsonFactory(); JsonNode node = mapper.readTree(factory.createJsonParser("\"/path/\"")); mapper.readValue(node, String.class); // => "/path/" node = mapper.readTree(factory.createJsonParser("\"\/path\/\""); mapper.readValue(node, String.class); // => "/path/"
This shows that whether or not the input is escaped that the JSON output produced in both cases is the unescaped forward slash.