encoding/json: RawMessage base64 encoded instead of directly embedded in json stream

3,289 views
Skip to first unread message

ron

unread,
Sep 17, 2013, 9:51:18 AM9/17/13
to golan...@googlegroups.com
Hello Gophers

I use RawMessage to precompute part of a json message.

RawMessage is a raw encoded JSON object. It implements Marshaler and Unmarshaler and can be used to delay JSON decoding or precompute a JSON encoding.


Following code shows the problem:

package main

import "encoding/json"

type S struct{ R json.RawMessage }

func main() {
s := S{json.RawMessage([]byte(`42`))}
b, _ := json.Marshal(s)
println(string(b)) // {"R":"NDI="} Expected: {"R":42}
}
 
Is this behaviour expected?
I have made a patch to go tip to fix this, should i send it for review?

Thank you for this great language!

Ron


 

Kyle Lemons

unread,
Sep 17, 2013, 7:23:25 PM9/17/13
to ron, golang-nuts


--
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...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

ron

unread,
Sep 19, 2013, 7:35:51 AM9/19/13
to golan...@googlegroups.com, ron
Thank you Kyle  completely missed the pointer in the receiver.
Message has been deleted

Johann Höchtl

unread,
Feb 26, 2014, 11:54:33 AM2/26/14
to golan...@googlegroups.com


Am Mittwoch, 18. September 2013 01:23:25 UTC+2 schrieb Kyle Lemons:
You need a pointer:

 
I have a struct like that

struct {
  Data interface{}
}

and Data should either be copied verbatim oder base64 encoded. data always ends up in base64. Where is the problem?

http://play.golang.org/p/tApLjVyrqN

Kevin Gillette

unread,
Feb 26, 2014, 5:23:22 PM2/26/14
to golan...@googlegroups.com, ron
So it was agreed that this doesn't constitute a bug, and thus cannot be fixed because of the Go 1 compatibility guarantee?

Johann Höchtl

unread,
Feb 27, 2014, 1:57:18 AM2/27/14
to golan...@googlegroups.com


Am Mittwoch, 26. Februar 2014 23:23:22 UTC+1 schrieb Kevin Gillette:
So it was agreed that this doesn't constitute a bug, and thus cannot be fixed because of the Go 1 compatibility guarantee?
Actually my previous post reports a new problem, not that of the OP but the formating turned out strange. I will post a new question.
Reply all
Reply to author
Forward
0 new messages