The string

"my custom encryption stuff"

is not valid JSON. Why does your type implement MarshalJSON if it does not 
produce JSON?

Lutz
________________________________
Von: Gert<mailto:gert.cuyk...@gmail.com>
Gesendet: ‎27.‎12.‎2019 07:55
An: golang-nuts<mailto:golang-nuts@googlegroups.com>
Betreff: [go-nuts] MarshalJSON() output encrypted json

https://play.golang.org/p/6qKkJhVsnU1

type Payload struct{}

func (p Payload) MarshalJSON() ([]byte, error) {
return []byte("my custom encryption stuf"), nil
}

func main() {
p := Payload{}
j, err := json.Marshal(p)
if err != nil {
fmt.Println(err)
}
fmt.Println(string(j))
}


json: error calling MarshalJSON for type main.Payload: invalid character 'm' 
looking for beginning of value


How do you skip the check from json.Marshal and just return the []byte directly 
whatever they are?

--
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to 
golang-nuts+unsubscr...@googlegroups.com<mailto:golang-nuts+unsubscr...@googlegroups.com>.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/554c8ca8-2bca-4321-9ee5-0524e28422a3%40googlegroups.com<https://groups.google.com/d/msgid/golang-nuts/554c8ca8-2bca-4321-9ee5-0524e28422a3%40googlegroups.com?utm_medium=email&utm_source=footer>.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/VI1PR06MB393377ABE87F1AFED2D325379E2A0%40VI1PR06MB3933.eurprd06.prod.outlook.com.

Reply via email to