From 454432a2c49977f95fbe311865873a93218b4be0 Mon Sep 17 00:00:00 2001 From: Bruce-sz Date: Thu, 30 Mar 2017 09:15:01 +0800 Subject: [PATCH] Update decimal.go --- bson/decimal.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/bson/decimal.go b/bson/decimal.go index 3d2f70020..7fe1c396a 100644 --- a/bson/decimal.go +++ b/bson/decimal.go @@ -37,6 +37,19 @@ type Decimal128 struct { h, l uint64 } +//impl Marshal Decimal128 to JSON +func (d *Decimal128) MarshalJSON() ([]byte, error) { + //do your serializing here + return []byte(d.String()), nil +} +//impl Unmarshal JSON to Decimal128 +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