I am using Jena 2.6.4.
The following code
String v = "Parnell Square East";
Literal l = ModelFactory.createDefaultModel().createTypedLiteral(
v, XSDDatatype.XSDstring);
System.out.println(l.toString());
Produces the following output:
Parnell Square East^^http://www.w3.org/2001/XMLSchema#string
which looks wrong to me: I would have expected:
“Parnell Square East”^^http://www.w3.org/2001/XMLSchema#string
From a quick look at the source code of LiteralImpl.java I see:
@Override public String toString() {
return asNode().toString( PrefixMapping.Standard, false );
}
Why is the second parameter (quoting) set to false?
If I do
String v = "Parnell Square East";
Literal l = ModelFactory.createDefaultModel().createTypedLiteral(v,
XSDDatatype.XSDstring);
System.out.println(l.asNode().toString(PrefixMapping.Standard, true));
I get the desired output
“Parnell Square East”^^http://www.w3.org/2001/XMLSchema#string
I just wonder why this is not the default behaviour?
Thanks,
marco
There’s no guarantee, implicit or explicit, that
toStringon any Jena node produces output that fits any particular serialization (e.g. Turtle). You might just as well ask whytoStringdoes not produce an XML node, or why the datatype is not abbreviated to a q-name. The view that Jena takes is thattoStringproduces enough information to be useful in debugging. Any requirements beyond that are application responsibilities.So saying, if you have a good use case feel free to submit a patch to the Jena Jira. Bear in mind though, that existing user code may have come to rely on the current behaviour, so switching would have some cost so you would need to make a strong case for change!