spray-json
spray-json copied to clipboard
Minor dead code in JsonPrinter
https://github.com/spray/spray-json/blob/master/src/main/scala/spray/json/JsonPrinter.scala#L79
Only the first line in the code here
case x if x <= 0xF => sb.append("\\u000").append(Integer.toHexString(x))
case x if x <= 0xFF => sb.append("\\u00").append(Integer.toHexString(x))
case x if x <= 0xFFF => sb.append("\\u0").append(Integer.toHexString(x))
case x => sb.append("\\u").append(Integer.toHexString(x))
Can ever execute - All character codes above 0x5c ('') are considered as not requiring encoding requiresEncoding returns false and therefore they are added to the output by the first case in the switch statement.
They do not require encoding as the json spec supports unicode rather than ascii as the base representation.
Yes, right. Maybe we should add a config switch somehow indicating whether to produce non-ascii chars directly in UTF-8 encoding in the output or whether to explicitly encode them via the \uXXXX notation.