Skip to content

json-ld: a native number or boolean @value with no @type keeps its RDF datatype - #2212

Merged
aaj3f merged 3 commits into
mainfrom
fix/jsonld-native-literal-types
Nov 11, 2026
Merged

aaj3f merged 3 commits into
mainfrom
fix/jsonld-native-literal-types

Conversation

@aaj3f

@aaj3f aaj3f commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

Fixes #2211

process_literal (fluree-graph-json-ld/src/adapter.rs) labelled every value object without @type as xsd:string, including what expansion makes of a bare 0, 1.5 or true, while keeping the native value. Now an untyped native value takes the datatype JSON-LD's RDF conversion gives it:

  • xsd:boolean for a boolean;
  • xsd:integer for an integral number;
  • xsd:double for any other number;
  • xsd:string only for a string.

That's the same rule the direct-scalar path in the same file already uses, so the two now agree. A declared @type still wins.

On blast radius, which was the thing I most wanted to be sure of. The two database sinks (flake_sink::term_literal_value, import_sink::term_literal_value) never read the declared datatype for a native value; they infer_datatype from it. So what transactions and bulk import store shouldn't change. template_sink does hash by the declared datatype, but it's only built in parse/rdf_text, which the Turtle/TriG parser feeds, not this adapter. The ones that do see a difference are GraphCollectorSink users (inline_shapes, inline_ontology, and anything that formats a collected graph): they now get "0"^^xsd:integer instead of "0".

Tests:

  • native_values_without_a_type_keep_their_rdf_datatype covers integer, double, boolean, string, and a declared xsd:long that still wins. It fails without the fix (xsd:string where xsd:integer is expected).
  • cargo test -p fluree-graph-json-ld (all suites), -p fluree-db-transact (452 passed), -p fluree-db-api inline (48) and import (177), -p fluree-graph-turtle -p fluree-graph-format, and cargo clippy -p fluree-graph-json-ld --all-targets --no-deps, all clean.

Once this lands, #2207 can drop its local workaround for the same thing (reader::request::parse_jsonld retypes these literals itself). The workaround is harmless alongside the fix, so there's no merge-order constraint between the two.

🤖 Generated with Claude Code

https://claude.ai/code/session_016CjYmSGfnxzJgMSzBESNee

…F datatype

`process_literal` labelled every value object without `@type` as
xsd:string, including `{"@value": 0}` and `{"@value": true}`, while keeping
the native value. The database sinks infer the datatype from the value, so
nothing stored changed, but a sink that keeps it (GraphCollectorSink) built
`Literal { Integer(0), xsd:string }`, which format_ntriples wrote as "0".

Now an untyped native value takes the datatype JSON-LD's RDF conversion
gives it: xsd:boolean, xsd:integer for an integral number, xsd:double
otherwise; a string stays xsd:string. Same rule as the direct-scalar path.

Fixes #2211

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016CjYmSGfnxzJgMSzBESNee

@jdorety jdorety left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Production sinks (FlakeSink, ImportSink) infer the datatype from the value, so stored data doesn't change. The regression test fails when the old datatype block is put back.

Nit, not blocking: the comment at adapter.rs:622 says integral numbers get xsd:integer, but the check is as_i64(). So 1.0, 1e3, and integers above i64::MAX get xsd:double. That's consistent with the stored Double value and with the bare-number path in list_item, but it differs from the JSON-LD spec. Maybe reword it to "a number that fits an i64".

aaj3f and others added 2 commits November 10, 2026 23:34
The comment said an integral number gets xsd:integer, but the check is
as_i64(), so 1.0, 1e3 and an integer past i64::MAX get xsd:double, as
their stored value and a bare number in a list do. It now says so, and
that JSON-LD's own conversion would call the first two integers.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@aaj3f

aaj3f commented Nov 11, 2026

Copy link
Copy Markdown
Contributor Author

Thank you, @jdorety, you're right, and the comment was promising more than the code does. 8d95f49 rewords it as you suggested: xsd:integer for a number that fits an i64, xsd:double for any other. It also spells out that 1.0, 1e3 and integers past i64::MAX are doubles, consistent with the stored value and with a bare number in a list, and notes that JSON-LD's own conversion would call the first two integers. It's a comment-only change. I left the behaviour alone since it matches what's stored, but happy to talk it through if you think the spec's reading is worth matching. I also merged origin/main in (99e1bc0), since the branch was six days behind. fmt, clippy on fluree-graph-json-ld with --all-targets, and its tests pass. I checked #2297 too: it touches expand.rs, not adapter.rs, and merge-tree with this branch is clean.

@aaj3f
aaj3f merged commit be309bd into main Nov 11, 2026
19 checks passed
@aaj3f
aaj3f deleted the fix/jsonld-native-literal-types branch November 11, 2026 18:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working as expected

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JSON-LD adapter labels a native number or boolean @value with no @type as xsd:string

2 participants