mailru / easyjson

Fast JSON serializer for golang.
MIT License
4.48k stars 421 forks source link

easyjson does not respect setting escape-html to false #183

Closed veqryn closed 6 years ago

veqryn commented 6 years ago
type Stuff struct {
    Thing string
}
v := &Stuff{Thing: `hello <&,.='"'=.,&> world`}

buffer := &bytes.Buffer{}
encoder := json.NewEncoder(buffer)
encoder.SetEscapeHTML(false)
_ = encoder.Encode(v)

The above will give the correct {"Thing":"hello <&,.='\"'=.,&> world"} when not using easyjson. With easyjson, you get: {"Thing":"hello \u003c\u0026,.='\"'=.,\u0026\u003e world"}

shmel1k commented 6 years ago

You can try to do something like

type UnescapableString string

func (s *UnescapableString) MarshalJSON() ([]byte, error) {
 // here you don't escape your string or smth like that
}
veqryn commented 6 years ago

I am fairly certain that the json package will still escape it after the fact. In any case, it is not feasible to change all my strings to this.

shmel1k commented 6 years ago

Sorry for the late answer

Did you try to use jwriter? jwriter has option 'NoEscapeHTML' you could try to use.

veqryn commented 6 years ago

I have not. That might be what I need.

shmel1k commented 6 years ago

Hello! Does my suggestion work? If does, can you close the issue, please? :)

veqryn commented 6 years ago

Looks like jwriter works.

If possible, it would be great if you could make json.Encoder work too.

shmel1k commented 6 years ago

Unfortunately, we can not work with json.Encoder now 😢

veqryn commented 6 years ago

Ok. Feel free to close this or keep it open in case you can support it in the future.

shmel1k commented 6 years ago

@rvasily close, please :)