From aebb98bab2bc8e792d3acde0dc778c0f123d6c32 Mon Sep 17 00:00:00 2001 From: Guillem Jover Date: Wed, 9 Oct 2019 13:16:35 +0200 Subject: [PATCH] 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 --- Build.PL | 2 +- lib/NGCP/API/Client.pm | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/Build.PL b/Build.PL index ce30bc0..5971e39 100644 --- a/Build.PL +++ b/Build.PL @@ -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, }, diff --git a/lib/NGCP/API/Client.pm b/lib/NGCP/API/Client.pm index 88c8d20..3a1d47d 100644 --- a/lib/NGCP/API/Client.pm +++ b/lib/NGCP/API/Client.pm @@ -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}; }