spray / spray-json

A lightweight, clean and simple JSON implementation in Scala
Apache License 2.0
969 stars 190 forks source link

Add UUID json format #313

Open atararaksin opened 5 years ago

atararaksin commented 5 years ago

This PR adds an instance of JsonFormat[UUID] as requested in https://github.com/spray/spray-json/issues/243. I'm not sure as to where to place this object, currently BasicFormats is my best guess, but feel free to request any changes.

Closes https://github.com/spray/spray-json/issues/243

plokhotnyuk commented 5 years ago

@atararaksin UUID.fromString behaves differently on different versions of Java and allows illegal (or non standart) string values...

Please consider to pick a more efficient and stable implementation, like here or here

atararaksin commented 5 years ago

@plokhotnyuk Thanks for pointing that out. I guess including fast-uuid as an external dependency is not a good option. Would it be appropriate (e.g. from the legal perspective) to borrow the implementation from jsoniter-scala?

plokhotnyuk commented 5 years ago

@atararaksin 1st one (from fast-uuid) is for sequences of characters.

While 2nd one (from jsoniter-scala) is for array of bytes - feel free to reuse if you will find something suitable there.

Philippus commented 5 years ago

This addition should make sure that uuid's follow RFC 4122, have a look at https://github.com/akka/akka-http/pull/2569 and https://github.com/akka/akka-http/pull/2596 for inspiration.

plokhotnyuk commented 5 years ago

@Philippus IMHO validation of the hexadecimal representation with dashes is enough... and limiting of allowed Msb bits will broke backward compatibility with NCS and custom extensions.

Also, using of regexp for that can be revised for more efficient implementation