mgo
mgo copied to clipboard
JSON Marshalling for Decimal128 type
Hi there, How open are maintainers of this project on adding JSON Marshaling for Decimal type. It is pretty simple change:
func (d *Decimal128) UnmarshalJSON(b []byte) error {
str, err := strconv.Unquote(string(b))
if err != nil {
return err
}
*d, err = ParseDecimal128(str)
return err
}
func (d Decimal128) MarshalJSON() ([]byte, error) {
return []byte(strconv.Quote(d.String())), nil
}
Probably it would be a bit more elegant to add encoding.TextMarshaler
which is respected by encoding/json
.
It's a common way to provide a general marshalling logic which is repected by many other marshallers, e.g. https://github.com/go-yaml/yaml (https://github.com/go-yaml/yaml/blob/v2/encode.go#L135)
Thanks for the reply @yalegko , you may be right. I will make a PR for implementing encoding.TextMarshaler
.
I see there are lot of PRs in the queue, but no commits to master last 6 months. Is this project alive?
I will make a PR for implementing
Woops, looks like I was too impatient, sorry :)
Is this project alive?
No idea, but suppose it uses development -> release model and dev branch seems fresh enough
Just made the same PR, but you put an effort for the tests :laughing: We are cool. I will close my PR :rofl:
I really like how Go made our 2 implementations to look exactly the same.
Hi @Dragomir-Ivanov and @yalegko,
Thanks a lot for taking the time to implement this, and sorry for the delay!
We are planning on cutting a last release shortly after which we'll stop supporting this repository, since the official driver is now out and available (https://github.com/mongodb/mongo-go-driver/).
We are sorting out all the existing PRs, and we'll run a battery of performance tests to make sure we don't degrade the driver. Until then, please feel free to use development or the new mgo official driver.
Thanks again! Esther
Hi @eminano, no problem for the delay, and thanks for merging into development
.