Not JSON-compatible
GoogleCodeExporter opened this issue · comments
Google Code Exporter commented
What steps will reproduce the problem?
1. Create a new UUID
2. Marshal said UUID
3. Unmarshal the result of 2 into a new UUID
What is the expected output? What do you see instead?
Both UUIDs should be equal. Instead, step 3 throws an Unmarshal error.
Marshaling occurs as is typical for byte slices--it is encoded as a string--but
Unmarshaling cannot unmarshal a string to type UUID.
What version of the product are you using? On what operating system?
This was confirmed in Go 1.2rc3 on the Go playground:
http://play.golang.org/p/BUo5pw9BAO. It is running against the latest master of
go-uuid, 7dda39b2e7d5.
Please provide any additional information below.
This should be simple enough to fix: extend the UUID type to implement
Marshaler and Unmarshaler. I would expect them to call json.Marshal on
id.String() (where id is a UUID), and json.Unmarshal, followed by Parse() on
the result.
If this were on Github or something similar, I'd submit a pull request.
Unfortunately, I'm unsure as to how to do that on Google Code. Instead, I've
implemented a variation on the Go Playground:
http://play.golang.org/p/OXjK4Jdd7w
This could be implemented by aliasing the UUID type locally an extending it,
but that seems like a silly wrapper to maintain, rather than adding two
functions to go-uuid.
Original issue reported on code.google.com by pa...@dramafever.com
on 17 Apr 2014 at 5:09
Google Code Exporter commented
I have also ran into this issue. In my own code I created a wrapper around the
uuid and had it implement Marshaler and Unmarshaler. It would be really nice
to see these implemented for uuid.
Original comment by ryan.mo...@greyrocksoft.com
on 20 May 2014 at 3:57
Google Code Exporter commented
Thank you, I am starting work on this now. Apparently I was not seeing mail
that indicated there were issues with go-uuid.
Original comment by bor...@google.com
on 1 Dec 2014 at 5:23
- Changed state: Started
Google Code Exporter commented
Original comment by bor...@google.com
on 1 Dec 2014 at 6:07
- Changed state: Fixed