MarshalText? On Fri, 2019-12-27 at 09:51 +0100, Gert Cuykens wrote: > Thanks, Which should I use instead then? The reason I use it is so I > can easily switch between regular json payloads for debugging and > encrypted/signed urlencode payloads > > On Fri, Dec 27, 2019 at 9:39 AM Axel Wagner > <axel.wagner...@googlemail.com> wrote: > > > > `MarshalJSON` needs to output a valid JSON value, according to the > > interface. If you don't need the result to be valid JSON, then > > don't use encoding/json. If you want to use JSON to use it as part > > of a larger value, you could output a JSON string (but you should > > familiarize yourself with what a JSON string can and can't contain > > - e.g. if your encrypted bytes contain quotes, that'll be > > problematic). > > > > On Fri, Dec 27, 2019 at 7:55 AM Gert <gert.cuyk...@gmail.com> > > wrote: > > > > > > 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. > > > To view this discussion on the web visit > > > https://groups.google.com/d/msgid/golang-nuts/554c8ca8-2bca-4321-9ee5-0524e28422a3%40googlegroups.com > > > . > >
-- 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/c232973276bc02ac657e3af3fef7878813b2bdee.camel%40kortschak.io.