You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by François-Paul Servant <fr...@gmail.com> on 2014/12/17 00:18:24 UTC
JSON-LD, problem with numbers on a non-US system
Hi,
there is a problem when reading JSON-LD containing numbers on a non-US system. See a test program below. I found that this is caused by a bug in
com.github.jsonldjava.core.RDFDataset
and I submitted an issue:
https://github.com/jsonld-java/jsonld-java/issues/131
Best,
fps
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import org.junit.Test;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
public class NumbersOnNonUSSystemJsonLDBugTest {
@Test
public final void test() {
try {
InputStream is = new ByteArrayInputStream(jsonLDString().getBytes("UTF-8"));
Model m = ModelFactory.createDefaultModel();
m.read(is, null, "JSON-LD");
m.write(System.out,"TTL");
// on a French system, you get
// WARN org.apache.jena.riot - Lexical form '1,0E2' not valid for datatype http://www.w3.org/2001/XMLSchema#decimal
// <http://www.ex.com/product>
// <http://schema.org/price> "1,0E2"^^<http://www.w3.org/2001/XMLSchema#decimal> .
} catch (UnsupportedEncodingException e) { e.printStackTrace();}
}
String jsonLDString() {
return
"{" +
"\"@id\": \"http://www.ex.com/product\"," +
"\"http://schema.org/price\": {" +
"\"@type\": \"http://www.w3.org/2001/XMLSchema#decimal\"," +
"\"@value\": 100.00" +
"}}}";
}
}
Re: JSON-LD, problem with numbers on a non-US system
Posted by Andy Seaborne <an...@apache.org>.
(conversation moved to jsonld-java/jsonld-java/issues/131 - more details
there)
It is wrong for UK as well. There are two problems.
The "1,0E2" is surface appearance.
The universal problem is the E -- a xsd:double.
Try with the 100.0 in "" -- @value is the lexical form.
http://www.w3.org/TR/json-ld/#typed-values
{
"@id": "http://www.ex.com/product" ,
"http://schema.org/price" : {
"@type": "http://www.w3.org/2001/XMLSchema#decimal" ,
"@value": "100.00"
}
}
Andy
On 16/12/14 23:18, François-Paul Servant wrote:
> Hi,
>
> there is a problem when reading JSON-LD containing numbers on a non-US system. See a test program below. I found that this is caused by a bug in
> com.github.jsonldjava.core.RDFDataset
> and I submitted an issue:
> https://github.com/jsonld-java/jsonld-java/issues/131
>
> Best,
> fps
>
> import java.io.ByteArrayInputStream;
> import java.io.InputStream;
> import java.io.UnsupportedEncodingException;
>
> import org.junit.Test;
>
> import com.hp.hpl.jena.rdf.model.Model;
> import com.hp.hpl.jena.rdf.model.ModelFactory;
>
> public class NumbersOnNonUSSystemJsonLDBugTest {
> @Test
> public final void test() {
> try {
> InputStream is = new ByteArrayInputStream(jsonLDString().getBytes("UTF-8"));
> Model m = ModelFactory.createDefaultModel();
> m.read(is, null, "JSON-LD");
> m.write(System.out,"TTL");
> // on a French system, you get
> // WARN org.apache.jena.riot - Lexical form '1,0E2' not valid for datatype http://www.w3.org/2001/XMLSchema#decimal
> // <http://www.ex.com/product>
> // <http://schema.org/price> "1,0E2"^^<http://www.w3.org/2001/XMLSchema#decimal> .
>
> } catch (UnsupportedEncodingException e) { e.printStackTrace();}
> }
>
> String jsonLDString() {
> return
> "{" +
> "\"@id\": \"http://www.ex.com/product\"," +
> "\"http://schema.org/price\": {" +
> "\"@type\": \"http://www.w3.org/2001/XMLSchema#decimal\"," +
> "\"@value\": 100.00" +
> "}}}";
> }
> }
>
>