Skip to content

Preserve numeric scalar typing when decoding JSON #1260

Description

@fglock

Summary

PerlOnJava's JSON decoder does not preserve the numeric scalar nature of JSON numbers. This breaks consumers that distinguish numbers from strings using Perl scalar flags, including JSON::Pointer.

Affected software

  • CPAN distribution: JSON-Pointer 0.07
  • Dependency: Class::Accessor::Lite 0.08
  • CPAN regression run: 20260904-185312-10032
  • Failing test: t/009_test.t

The complete upstream suite passes under system Perl: 11 test files and 51 tests. PerlOnJava reproduces the failure on both the JVM and interpreter backends.

Minimal reproducer

use JSON;
use JSON::Pointer;

my $document = decode_json('{"a":1}');
print JSON::Pointer->test($document, '/a', 1), "\n";

Expected output:

1

PerlOnJava output:

0

Root cause

JSON::Pointer::test uses B::svref_2object flags to distinguish numeric and string values:

my $flags = B::svref_2object(\$value)->FLAGS;
return (($flags & (B::SVp_IOK | B::SVp_NOK)) && !($flags & B::SVp_POK));

Under standard Perl, decode_json gives the decoded number numeric flags. Under PerlOnJava, the decoded number is represented as a string-only scalar (POK without IOK/NOK). JSON::Pointer therefore treats the document value 1 as a string while the expected literal 1 is numeric, and returns false.

Impact

This affects JSON consumers that rely on Perl's numeric/string scalar distinction or inspect B flags. In JSON::Pointer, traversal and pointer escaping work correctly, but numeric equality checks for values decoded from JSON fail. The regression caused 9 RFC example cases in t/009_test.t to fail.

Expected fix

Ensure JSON numeric tokens produce numeric PerlOnJava scalars with behavior equivalent to system Perl, including numeric coercion/flag semantics, or provide a runtime-compatible numeric-type mechanism for code using B flags. Preserve the distinction between JSON numbers and JSON strings.

Add permanent regression coverage for decoded numeric values versus numeric and string expected values, and validate both execution backends.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:cpan-portCPAN compatibility ports and providersarea:runtimeCore Perl runtime semanticsbugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions