Treat incoming JSON as latin1
authorDan Scott <dscott@laurentian.ca>
Sun, 18 Jan 2015 18:04:04 +0000 (13:04 -0500)
committerDan Scott <dscott@laurentian.ca>
Sun, 18 Jan 2015 18:04:04 +0000 (13:04 -0500)
xID appears to return unencoded values in its JSON (such as
hex 333 in the response to ISBN 9784642033053) so treat the
JSON as though it were encoded in latin1; we're not using
any of the encoded string values anyway.

Signed-off-by: Dan Scott <dscott@laurentian.ca>
Open-ILS/src/sql/Pg/update_marc_records_in_database.sql

index 133dbb1..8d9ba26 100644 (file)
@@ -10,6 +10,9 @@ use JSON::XS;
 
 MARC::Charset->assume_unicode(1);
 
+my $json = new JSON::XS;
+$json->latin1(1);
+
 my $q = spi_prepare('SELECT marc FROM biblio.record_entry WHERE id = $1', 'BIGINT');
 my $marc = spi_exec_prepared($q, $_[0])->{rows}->[0]->{marc};
 
@@ -105,7 +108,7 @@ if ($lccn_number) {
     $lccn_number =~ s{^\s*(\S+)\s*$}{$1};
     $lccn->update('a', $lccn_number);
     my $response = $ua->get("http://xisbn.worldcat.org/webservices/xid/lccn/$lccn_number?method=getMetadata&format=json&fl=*");
-    my $metadata = decode_json($response->decoded_content);
+    my $metadata = $json->decode($response->decoded_content);
     if ($response->is_success) {
         $oclc_number = $metadata->{'list'}->[0]->{'oclcnum'}->[0];
         $owi_number = $metadata->{'list'}->[0]->{'owi'}->[0];
@@ -128,23 +131,23 @@ if ($lccn_number) {
 
         my $response = $ua->get("http://xisbn.worldcat.org/webservices/xid/isbn/$isbn?method=getMetadata&format=json&fl=*");
         next unless $response->is_success;
-        my $metadata = decode_json($response->decoded_content);
+        my $metadata = $json->decode($response->decoded_content);
         if (exists $metadata->{'list'}->[0]->{'lccn'} and !$lccn_number) {
             $lccn_number = $metadata->{'list'}->[0]->{'lccn'}->[0];
             my $nf = MARC::Field->new('010', '', '', 'a' => "$lccn_number");
             $record->insert_fields_ordered($nf);
             my $response = $ua->get("http://xisbn.worldcat.org/webservices/xid/lccn/$lccn_number?method=getMetadata&format=json&fl=*");
             if ($response->is_success) {
-                my $metadata = decode_json($response->decoded_content);
-                $owi_number = $metadata->{'list'}->[0]->{'owi'}->[0];
+                my $lccn_metadata = $json->decode($response->decoded_content);
+                $owi_number = $lccn_metadata->{'list'}->[0]->{'owi'}->[0];
             }
         }
         if (exists $metadata->{'list'}->[0]->{'oclcnum'} and !$oclc_number) {
             $oclc_number = $metadata->{'list'}->[0]->{'oclcnum'}->[0];
             my $response = $ua->get("http://xisbn.worldcat.org/webservices/xid/oclcnum/$oclc_number?method=getMetadata&format=json&fl=*");
             if ($response->is_success) {
-                my $metadata = decode_json($response->decoded_content);
-                $owi_number = $metadata->{'list'}->[0]->{'owi'}->[0];
+                my $isbn_metadata = $json->decode($response->decoded_content);
+                $owi_number = $isbn_metadata->{'list'}->[0]->{'owi'}->[0];
             }
         }
     }