Closed pjvds closed 11 years ago
Might be worth holding off on this till Go 1.2, which will implement a generic Marshalling API that will work for any encoder / decoder.
What I've done in my apps is make my own type:
type UUID uuid.UUID
on which I then put the MarshalJSON and UnmarshalJSON methods.
Version 1.2 is not released until december and there are still quite some people writing Go 1.0 and 1.1 code. Regarding aliasing the type, I value a properly tested implementation above writing my own.
Do you think it adds to much overhead to the package?
I don't really have anything against the change, just putting that out there for consideration.
Good suggestion, although the json.Marshal and json.Unmarshal take some steps before they actually start working on the marshalling. Also this gives the ability to return better error messages.
I would prefer to hold this until unified marshaling API is released. I'd like to keep this lib as simple as possible. Also, i really don't like the implementation pushed along with this pull request, @kisielk comments explain it.
I am using the gouuid library for the identifiers of my objects. These objects get stored in a document store and are exposed in a REST api. Both API and database marshal the object to the JSON format. Currently the
uuid.UUID
does not implement thejson.Marshaller
andjson.Unmarshaller
interface. This pull request changes that.I have added the
MarshalJSON
andUnmarshalJSON
to theuuid.UUID
type, which are covered by tests. The JSON value is a hex string as returned by theuuid.UUID.String
method.