From 7f17de6ab7bf62accc165ae21b0246262556dc46 Mon Sep 17 00:00:00 2001 From: Bruce-sz Date: Thu, 30 Mar 2017 12:40:10 +0800 Subject: [PATCH] Update decimal.go marshal/unMarshal json for decimal128 --- bson/decimal.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/bson/decimal.go b/bson/decimal.go index 3d2f70020..57c9e8fc6 100644 --- a/bson/decimal.go +++ b/bson/decimal.go @@ -37,6 +37,20 @@ type Decimal128 struct { h, l uint64 } +//marshal json +func (d *Decimal128) MarshalJSON() ([]byte, error) { + //do your serializing here + return []byte(d.String()), nil +} +//unMarshal json +func (d *Decimal128) UnmarshalJSON(b []byte) error { + //do your serializing here + d1, err := ParseDecimal128(string(b)) + d.h = d1.h + d.l = d1.l + return err +} + func (d Decimal128) String() string { var pos int // positive sign var e int // exponent