spray-json icon indicating copy to clipboard operation
spray-json copied to clipboard

Minor dead code in JsonPrinter

Open rorygraves opened this issue 11 years ago • 1 comments

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.

rorygraves avatar Aug 06 '14 14:08 rorygraves

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.

sirthias avatar Aug 07 '14 10:08 sirthias