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

Add UUID json format

Open atararaksin opened this issue 6 years ago • 5 comments

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

atararaksin avatar Jul 29 '19 18:07 atararaksin

@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

plokhotnyuk avatar Jul 29 '19 18:07 plokhotnyuk

@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?

atararaksin avatar Jul 30 '19 11:07 atararaksin

@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.

plokhotnyuk avatar Jul 30 '19 12:07 plokhotnyuk

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.

Philippus avatar Jul 31 '19 03:07 Philippus

@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

plokhotnyuk avatar Jul 31 '19 04:07 plokhotnyuk