|
18 | 18 | package cz.cvut.kbss.jsonld.serialization;
|
19 | 19 |
|
20 | 20 | import cz.cvut.kbss.jopa.model.annotations.Id;
|
| 21 | +import cz.cvut.kbss.jopa.model.annotations.OWLAnnotationProperty; |
21 | 22 | import cz.cvut.kbss.jopa.model.annotations.OWLClass;
|
22 | 23 | import cz.cvut.kbss.jopa.model.annotations.OWLDataProperty;
|
| 24 | +import cz.cvut.kbss.jopa.vocabulary.DC; |
| 25 | +import cz.cvut.kbss.jopa.vocabulary.XSD; |
23 | 26 | import cz.cvut.kbss.jsonld.ConfigParam;
|
24 | 27 | import cz.cvut.kbss.jsonld.JsonLd;
|
25 | 28 | import cz.cvut.kbss.jsonld.common.IdentifierUtil;
|
|
43 | 46 | import cz.cvut.kbss.jsonld.serialization.serializer.ValueSerializer;
|
44 | 47 | import cz.cvut.kbss.jsonld.serialization.util.BufferedJsonGenerator;
|
45 | 48 | import jakarta.json.Json;
|
| 49 | +import jakarta.json.JsonArray; |
| 50 | +import jakarta.json.JsonObject; |
46 | 51 | import jakarta.json.JsonValue;
|
47 | 52 | import org.eclipse.rdf4j.model.BNode;
|
| 53 | +import org.eclipse.rdf4j.model.IRI; |
48 | 54 | import org.eclipse.rdf4j.model.Model;
|
49 | 55 | import org.eclipse.rdf4j.model.Statement;
|
50 | 56 | import org.eclipse.rdf4j.model.ValueFactory;
|
|
73 | 79 | import java.util.stream.IntStream;
|
74 | 80 |
|
75 | 81 | import static cz.cvut.kbss.jsonld.environment.IsIsomorphic.isIsomorphic;
|
| 82 | +import static cz.cvut.kbss.jsonld.environment.TestUtil.parseAndExpand; |
76 | 83 | import static org.hamcrest.MatcherAssert.assertThat;
|
77 | 84 | import static org.hamcrest.Matchers.hasItem;
|
78 | 85 | import static org.hamcrest.Matchers.hasItems;
|
@@ -473,4 +480,44 @@ void serializationSerializesAttributeWithCollectionOfEnumConstantsMappedToIndivi
|
473 | 480 | final Model actual = readJson(jsonWriter.getResult());
|
474 | 481 | assertThat(actual, isIsomorphic(expected));
|
475 | 482 | }
|
| 483 | + |
| 484 | + @Test |
| 485 | + void serializationIncludesDatatypeOfNumericLiterals() throws Exception { |
| 486 | + final Product p = new Product(); |
| 487 | + p.price = 155.15; |
| 488 | + p.name = "Test product"; |
| 489 | + p.uri = Generator.generateUri(); |
| 490 | + sut.serialize(p); |
| 491 | + final JsonArray result = parseAndExpand(jsonWriter.getResult()); |
| 492 | + final JsonObject obj = result.getJsonObject(0); |
| 493 | + final JsonArray priceAtt = obj.getJsonArray("https://schema.org/price"); |
| 494 | + assertEquals(1, priceAtt.size()); |
| 495 | + assertEquals(XSD.DOUBLE, priceAtt.getJsonObject(0).getString("@type")); |
| 496 | + assertEquals(p.price.toString(), priceAtt.getJsonObject(0).getJsonNumber("@value").toString()); |
| 497 | + } |
| 498 | + |
| 499 | + @OWLClass(iri = Vocabulary.DEFAULT_PREFIX + "Product") |
| 500 | + private static class Product implements GeneratesRdf { |
| 501 | + @Id |
| 502 | + private URI uri; |
| 503 | + |
| 504 | + @OWLAnnotationProperty(iri = DC.Terms.TITLE) |
| 505 | + private String name; |
| 506 | + |
| 507 | + @OWLDataProperty(iri = "https://schema.org/price") |
| 508 | + private Double price; |
| 509 | + |
| 510 | + @Override |
| 511 | + public URI getUri() { |
| 512 | + return uri; |
| 513 | + } |
| 514 | + |
| 515 | + @Override |
| 516 | + public void toRdf(Model model, ValueFactory vf, Set<URI> visited) { |
| 517 | + final IRI subject = vf.createIRI(uri.toString()); |
| 518 | + model.add(subject, RDF.TYPE, vf.createIRI(Vocabulary.DEFAULT_PREFIX + "Product")); |
| 519 | + model.add(subject, vf.createIRI(DC.Terms.TITLE), vf.createLiteral(name)); |
| 520 | + model.add(subject, vf.createIRI("https://schema.org/price"), vf.createLiteral(price)); |
| 521 | + } |
| 522 | + } |
476 | 523 | }
|
0 commit comments