From c2a76fa901e6e652191662eda2afd1098cafb2b7 Mon Sep 17 00:00:00 2001 From: Pierre Mdawar Date: Wed, 16 Oct 2024 14:58:25 +0300 Subject: [PATCH] fix: avoid redundant byte conversion in UnmarshalText --- codec.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/codec.go b/codec.go index e4ed66e..38eedc2 100644 --- a/codec.go +++ b/codec.go @@ -248,7 +248,12 @@ func (d *Decimal) UnmarshalJSON(data []byte) error { // MarshalText implements the [encoding.TextMarshaler] interface. func (d Decimal) MarshalText() ([]byte, error) { - return []byte(d.String()), nil + if !d.coef.overflow() { + // Return without quotes. + return d.bytesU128(true, false), nil + } + + return []byte(d.stringBigInt(true)), nil } // UnmarshalText implements the [encoding.TextUnmarshaler] interface.