Bug 24606: (QA follow-up) Fix encoding/decoding

We should use OO interface and leave encoding to database
layer.

Test plan:
Add a new item template containing real Unicode chars.
Save. Apply on new item.

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Marcel de Rooy 2022-11-17 10:02:08 +00:00 committed by Tomas Cohen Arazi
parent 923609f42e
commit 6744cd6612
Signed by: tomascohen
GPG key ID: 0A272EA1B2F3C15F

View file

@ -41,7 +41,7 @@ sub store {
my ($self) = @_;
if ( ref( $self->contents ) eq 'HASH' ) {
$self->contents( encode_json( $self->contents ) );
$self->contents( $self->_json->encode( $self->contents ) );
}
$self = $self->SUPER::store;
@ -56,11 +56,20 @@ Returns a deserilized perl structure of the JSON formatted contents
sub decoded_contents {
my ($self) = @_;
return decode_json( encode_utf8($self->contents) ) if $self->contents;
return $self->_json->decode($self->contents) if $self->contents;
}
=head2 Internal methods
=head3 _json
=cut
sub _json {
my $self = shift;
$self->{_json} //= JSON->new; # Keep utf8 off !
}
=head3 _type
=cut