TT#68300 Switch to modern JSON::XS and encode/decode_json()

The to/from_json() are deprecated functions, which we should not be
using. Switch to the new ones, which also means we can stop encoding
the strings to and from UTF-8 explicitly.

Change-Id: Ie29371d532a51a3a62d54c35d22a6d488fe1b513
changes/99/34099/2
Guillem Jover 6 years ago
parent 7138971163
commit aebb98bab2

@ -7,7 +7,7 @@ my $builder = Module::Build->new(
requires => {
'Config::Tiny' => 0,
'IO::Socket::SSL' => 0,
'JSON' => 0,
'JSON::XS' => 0,
'LWP::UserAgent' => 0,
'Readonly' => 0,
},

@ -3,11 +3,10 @@ use strict;
use warnings;
use English qw(-no_match_vars);
use Config::Tiny;
use JSON qw(to_json);
use JSON::XS;
use IO::Socket::SSL;
use LWP::UserAgent;
use Readonly;
use Encode;
use URI;
my $config;
@ -96,7 +95,7 @@ sub request {
my $req = $self->_create_req($method, $self->_get_url($urlbase,$uri));
if ($data) {
$req->content(Encode::encode_utf8(to_json($data)));
$req->content(encode_json($data));
}
my $res = $ua->request($req);
@ -165,7 +164,7 @@ use warnings;
use strict;
use parent qw(HTTP::Response);
use JSON qw(from_json);
use JSON::XS;
sub new {
my ($class, $res_obj) = @_;
@ -180,7 +179,7 @@ sub new {
sub as_hash {
my $self = shift;
return $self->{_cached} if $self->{_cached};
$self->{_cached} = from_json($self->content, { utf8 => 1 });
$self->{_cached} = decode_json($self->content);
return $self->{_cached};
}

Loading…
Cancel
Save