⚡ Sangsakala Proxy 🏠 Home
Skip to content

Commit 95cbd49

Browse files
committed
rdfToJson edge case when object = subject and predicate = rdf:type
1 parent a88eacf commit 95cbd49

2 files changed

Lines changed: 33 additions & 1 deletion

File tree

‎core/src/main/java/com/github/jsonldjava/core/JsonLdApi.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2001,7 +2001,8 @@ public List<Object> fromRDF(final RDFDataset dataset, boolean noDuplicatesInData
20012001

20022002
// 3.5.4)
20032003
if (RDF_TYPE.equals(predicate) && (object.isIRI() || object.isBlankNode())
2004-
&& !opts.getUseRdfType() && !nodes.containsKey(object.getValue())) {
2004+
&& !opts.getUseRdfType() &&
2005+
(!nodes.containsKey(object.getValue()) || subject.equals(object.getValue()))) {
20052006
JsonLdUtils.mergeValue(node, JsonLdConsts.TYPE, object.getValue());
20062007
continue;
20072008
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.github.jsonldjava.core;
2+
3+
import org.junit.Test;
4+
5+
import static org.junit.Assert.assertEquals;
6+
7+
public class JsonLdToRdfTest {
8+
9+
@Test
10+
public void testIssue301() throws JsonLdError {
11+
final RDFDataset rdf = new RDFDataset();
12+
rdf.addTriple(
13+
"http://www.w3.org/2002/07/owl#Class",
14+
"http://www.w3.org/1999/02/22-rdf-syntax-ns#type",
15+
"http://www.w3.org/2002/07/owl#Class");
16+
final JsonLdOptions opts = new JsonLdOptions();
17+
opts.setUseRdfType(Boolean.FALSE);
18+
opts.setProcessingMode(JsonLdOptions.JSON_LD_1_0);
19+
20+
final Object out = new JsonLdApi(opts).fromRDF(rdf, true);
21+
assertEquals("[{@id=http://www.w3.org/2002/07/owl#Class, @type=[http://www.w3.org/2002/07/owl#Class]}]",
22+
out.toString());
23+
24+
opts.setUseRdfType(Boolean.TRUE);
25+
26+
final Object out2 = new JsonLdApi(opts).fromRDF(rdf, true);
27+
assertEquals("[{@id=http://www.w3.org/2002/07/owl#Class, http://www.w3.org/1999/02/22-rdf-syntax-ns#type=[{@id=http://www.w3.org/2002/07/owl#Class}]}]",
28+
out2.toString());
29+
}
30+
31+
}

0 commit comments

Comments
 (0)