Skip to content

Commit 8abbbee

Browse files
committed
feat: Reflect explicitly XSD-typed Literals in JSON-LD serialization
Supplying an XSD type argument to the rdflib.Literal datatype parameter should be reflected in JSON-LD serializations. Closes: RDFLib#2812
1 parent cb5d058 commit 8abbbee

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

rdflib/plugins/serializers/jsonld.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,15 @@
3636
# graphs.
3737

3838
from __future__ import annotations
39-
39+
from typing import Any, Dict, IO, List, Optional
4040
import warnings
41-
from typing import IO, Any, Dict, List, Optional
4241

4342
from rdflib.graph import DATASET_DEFAULT_GRAPH_ID, Graph, _ObjectType
4443
from rdflib.namespace import RDF, XSD
4544
from rdflib.serializer import Serializer
4645
from rdflib.term import BNode, IdentifiedNode, Identifier, Literal, URIRef
4746

48-
from ..shared.jsonld.context import UNDEF, Context
47+
from ..shared.jsonld.context import Context, UNDEF
4948
from ..shared.jsonld.keys import CONTEXT, GRAPH, ID, LANG, LIST, SET, VOCAB
5049
from ..shared.jsonld.util import _HAS_ORJSON, json, orjson
5150

@@ -393,11 +392,8 @@ def to_raw_value(
393392
else:
394393
v = str(o)
395394
if o.datatype:
396-
if native:
397-
if self.context.active:
398-
return v
399-
else:
400-
return {context.value_key: v}
395+
if native and self.context.active:
396+
return v
401397
return {
402398
context.type_key: context.to_symbol(o.datatype),
403399
context.value_key: v,

0 commit comments

Comments
 (0)