add UnmarshalJSON for pgtype Numeric
This commit is contained in:
committed by
Jack Christensen
parent
384a581e99
commit
766d2bba4f
@@ -240,6 +240,18 @@ func (n Numeric) MarshalJSON() ([]byte, error) {
|
||||
return n.numberTextBytes(), nil
|
||||
}
|
||||
|
||||
func (n *Numeric) UnmarshalJSON(src []byte) error {
|
||||
if bytes.Compare(src, []byte(`null`)) == 0 {
|
||||
*n = Numeric{}
|
||||
return nil
|
||||
}
|
||||
if bytes.Compare(src, []byte(`"NaN"`)) == 0 {
|
||||
*n = Numeric{NaN: true, Valid: true}
|
||||
return nil
|
||||
}
|
||||
return scanPlanTextAnyToNumericScanner{}.Scan(src, n)
|
||||
}
|
||||
|
||||
// numberString returns a string of the number. undefined if NaN, infinite, or NULL
|
||||
func (n Numeric) numberTextBytes() []byte {
|
||||
intStr := n.Int.String()
|
||||
|
||||
Reference in New Issue
Block a user