geofffranks / json-api

A perl module to simplify interaction with JSON APIs
Other
6 stars 6 forks source link

_encode should use encode_json, not to_json #10

Open eritain opened 1 year ago

eritain commented 1 year ago

JSON::encode_json produces a UTF-8 encoded binary string, which is what HTTP::Request expects.

JSON::to_json produces the corresponding Unicode string, which can coincidentally be byte-identical to the binary string depending on the codepoints used and on your Perl's internal representation, but can also be something else.

eritain commented 1 year ago

Well, not quite coincidentally. Perl adjusts its internal representations to the codepoints in the string, for backward compatibility with old code that assumes ASCII (or maybe Latin-1). Be that as it may, when you step outside that character set, HTTP::Request errors out: "HTTP::Message content must be bytes"