Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

math/big: big.Rat has not MarshallJSON/UnmarshallJSON methods #64546

Closed
iuliananz opened this issue Dec 4, 2023 · 1 comment
Closed

math/big: big.Rat has not MarshallJSON/UnmarshallJSON methods #64546

iuliananz opened this issue Dec 4, 2023 · 1 comment

Comments

@iuliananz
Copy link

iuliananz commented Dec 4, 2023

Go version

go1.21.4

What operating system and processor architecture are you using (go env)?

big.Rat doesn't have MarshallJSON and UnmarshallJSON methods. Is this intentional?

I noticed it while trying to save an object containing a big.Rat field in mongodb, field comes up empty, due to no marshalling.

What did you do?

package main

import (
	"encoding/json"
	"fmt"
	"math/big"
)

type SomeStructure struct {
	Name     string
	RatField big.Rat
}

func main() {
	rat := big.NewRat(10, 3)
	obj := SomeStructure{
		Name:     "Object name",
		RatField: *rat,
	}
	result, err := json.Marshal(obj)
	if err != nil {
		fmt.Println(err.Error())
		return
	}
	fmt.Printf("Json string: %s", string(result))
}

What did you expect to see?

Json string: {"Name":"Object name","RatField":{a: 10, b: 3}}

What did you see instead?

Json string: {"Name":"Object name","RatField":{}}
@seankhliao
Copy link
Member

it has MarshalText/UnmarshalText if you use pointers

Unlike many projects, the Go project does not use GitHub Issues for general discussion or asking questions. GitHub Issues are used for tracking bugs and proposals only.

For questions please refer to https://github.com/golang/go/wiki/Questions

@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Dec 5, 2023
@golang golang locked and limited conversation to collaborators Dec 4, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants