Open jrmarkle opened 6 years ago
This is great, thank you!
My only concern is changing the marshalerFaster
interface. I don't have an alternative though.
It's an internal interface but yeah, the only alternative I see is to add the flag to fflib.EncodingBuffer
somehow and that seemed like a worse option.
can this get merged?
I'm using
buf, err := ffjson.Marshal(&item)
and < is getting escaped in serialized values. I'd like to disable that, and this pull request looks apropos, but it doesn't seem to expose the escapeHTML flag through to the user...?
I'm using
buf, err := ffjson.Marshal(&item)
and < is getting escaped in serialized values. I'd like to disable that, and this pull request looks apropos, but it doesn't seem to expose the escapeHTML flag through to the user...?
IIRC it should work the same way as the standard library. You need to create an encoder and configure it. eg:
buf := new(bytes.Buffer)
enc := ffjson.NewEncoder(buf)
enc.SetEscapeHTML(false)
enc.Encode(item)
Doesn't that lose the speed advantage of ffjson.Marshal()...?
(I wonder if a generation-time flag might be a good idea... then you wouldn't have to thread that option through as much, the generated code would just have true or false hardcoded. It'd work for my use case. And it would avoid changing that interface...?)
https://github.com/pquerna/ffjson/issues/260 makes it a little hard to play around with this...
Doesn't that lose the speed advantage of ffjson.Marshal()...?
Right, sorry. It should be ffjson.NewEncoder
in the example (now corrected).
I'm testing the change locally. To use my changed copy, I had to add this to go.mod in the app using ffjson:
replace github.com/pquerna/ffjson => /Users/dkegel/go/src/github.com/pquerna/ffjson
And it works! Well, kind of.
Oddly, even though I'm calling enc.SetEscapeHTML(false) both places I encode, in one case foo.MarshalJSON is being called, which hardcodes it to true.
Possible fix for #237