[livejournal] r17432: LJSUP-6928 (We should take only public t...
Committer: ailyin
LJSUP-6928 (We should take only public tweets/re-tweets (public account).)U trunk/cgi-bin/LJ/JSON.pm
Modified: trunk/cgi-bin/LJ/JSON.pm
===================================================================
--- trunk/cgi-bin/LJ/JSON.pm 2010-09-22 09:21:45 UTC (rev 17431)
+++ trunk/cgi-bin/LJ/JSON.pm 2010-09-22 09:29:25 UTC (rev 17432)
@@ -60,9 +60,9 @@
return \@ret;
}
- # unknown type; for now, silently ignore it.
- # TODO: better error handling?
- return undef;
+ # unknown type; let the subclass decode it to a scalar
+ # (base class function defaults to plain stringification)
+ return $sub->($class->decode_unknown_type($what));
}
sub traverse_fix_encoding {
@@ -80,7 +80,12 @@
return Encode::encode("iso-8859-1", $scalar);
});
+}
+sub decode_unknown_type {
+ my ($class, $what) = @_;
+
+ return "$what";
}
package LJ::JSON::XS;
@@ -105,6 +110,16 @@
return $decoded;
}
+sub decode_unknown_type {
+ my ($class, $what) = @_;
+
+ # booleans get converted to undef for false and 1 for true
+ return $what ? 1 : undef if JSON::XS::is_bool($what);
+
+ # otherwise, stringify
+ return "$what";
+}
+
1;
package LJ::JSON::JSONv2;
@@ -129,6 +144,16 @@
return $decoded;
}
+sub decode_unknown_type {
+ my ($class, $what) = @_;
+
+ # booleans get converted to undef for false and 1 for true
+ return $what ? 1 : undef if JSON::is_bool($what);
+
+ # otherwise, stringify
+ return "$what";
+}
+
1;
package LJ::JSON::JSONv1;
