Skip to content

Commit 1bdfcc9

Browse files
authored
Merge pull request #86 from kbss-cvut/development
[0.15.4] Release
2 parents d40a39b + ad06583 commit 1bdfcc9

File tree

5 files changed

+97
-7
lines changed

5 files changed

+97
-7
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# JB4JSON-LD Changelog
22

3+
## 0.15.4 - 2025-08-11
4+
- Fix an issue with deserializing typed literals into `@Properties` (Bug #84).
5+
36
## 0.15.3 - 2025-07-30
47
- Improve the consistency of typed literals serialization - use native JSON types when possible (Bug #81).
58
- Dependency updates: JOPA 2.4.4.

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>cz.cvut.kbss.jsonld</groupId>
88
<artifactId>jb4jsonld</artifactId>
9-
<version>0.15.3</version>
9+
<version>0.15.4</version>
1010
<name>JB4JSON-LD</name>
1111
<description>Java Binding for JSON-LD allows serialization and deserialization of Java POJOs to/from JSON-LD.
1212
This is the core implementation, which has to be integrated with Jackson, Jersey etc.

src/main/java/cz/cvut/kbss/jsonld/deserialization/expanded/CollectionDeserializer.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,20 @@ private void resolveValue(JsonObject value) {
7676
} else if (value.containsKey(JsonLd.LANGUAGE)) {
7777
assert value.containsKey(JsonLd.VALUE);
7878
instanceBuilder.addValue(
79-
new LangString(ValueUtils.stringValue(ValueUtils.getValue(value)), ValueUtils.stringValue(value.get(JsonLd.LANGUAGE))));
79+
new LangString(ValueUtils.stringValue(ValueUtils.getValue(value)),
80+
ValueUtils.stringValue(value.get(JsonLd.LANGUAGE))));
8081
} else if (instanceBuilder.isCurrentCollectionProperties()) {
81-
// If we are deserializing an object into @Properties, just extract the identifier and put it into the map
82-
if (!value.containsKey(JsonLd.ID)) {
82+
if (value.containsKey(JsonLd.TYPE) && value.containsKey(JsonLd.VALUE)) {
83+
instanceBuilder.addValue(
84+
XSDTypeCoercer.coerceType(ValueUtils.stringValue(ValueUtils.getValue(value)),
85+
ValueUtils.stringValue(value.get(JsonLd.TYPE))));
86+
} else if (!value.containsKey(JsonLd.ID)) {
8387
throw new MissingIdentifierException(
8488
"Cannot put an object without an identifier into @Properties. Object: " + value);
89+
} else {
90+
// If we are deserializing an object into @Properties, just extract the identifier and put it into the map
91+
instanceBuilder.addValue(URI.create(ValueUtils.stringValue(value.get(JsonLd.ID))));
8592
}
86-
instanceBuilder.addValue(URI.create(ValueUtils.stringValue(value.get(JsonLd.ID))));
8793
} else {
8894
final Class<?> elementType = instanceBuilder.getCurrentCollectionElementType();
8995
new ObjectDeserializer(instanceBuilder, config, elementType).processValue(value);
@@ -126,9 +132,11 @@ private void extractLiteralValue(JsonObject value) {
126132
final JsonValue val = value.get(JsonLd.VALUE);
127133
if (value.containsKey(JsonLd.TYPE)) {
128134
instanceBuilder
129-
.addValue(property, XSDTypeCoercer.coerceType(ValueUtils.stringValue(val), ValueUtils.stringValue(value.get(JsonLd.TYPE))));
135+
.addValue(property, XSDTypeCoercer.coerceType(ValueUtils.stringValue(val),
136+
ValueUtils.stringValue(value.get(JsonLd.TYPE))));
130137
} else if (value.containsKey(JsonLd.LANGUAGE)) {
131-
instanceBuilder.addValue(property, new LangString(ValueUtils.stringValue(val), ValueUtils.stringValue(value.get(JsonLd.LANGUAGE))));
138+
instanceBuilder.addValue(property, new LangString(ValueUtils.stringValue(val),
139+
ValueUtils.stringValue(value.get(JsonLd.LANGUAGE))));
132140
} else {
133141
instanceBuilder.addValue(property, ValueUtils.literalValue(val));
134142
}

src/test/java/cz/cvut/kbss/jsonld/deserialization/expanded/ExpandedJsonLdDeserializerTest.java

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import cz.cvut.kbss.jsonld.environment.model.Organization;
4242
import cz.cvut.kbss.jsonld.environment.model.OwlPropertyType;
4343
import cz.cvut.kbss.jsonld.environment.model.Person;
44+
import cz.cvut.kbss.jsonld.environment.model.PersonWithTypedProperties;
4445
import cz.cvut.kbss.jsonld.environment.model.Role;
4546
import cz.cvut.kbss.jsonld.environment.model.Study;
4647
import cz.cvut.kbss.jsonld.environment.model.StudyOnPersons;
@@ -75,6 +76,7 @@
7576
import static org.hamcrest.Matchers.anyOf;
7677
import static org.hamcrest.Matchers.containsString;
7778
import static org.hamcrest.Matchers.hasItems;
79+
import static org.hamcrest.Matchers.hasKey;
7880
import static org.hamcrest.Matchers.instanceOf;
7981
import static org.junit.jupiter.api.Assertions.assertEquals;
8082
import static org.junit.jupiter.api.Assertions.assertFalse;
@@ -891,4 +893,49 @@ void deserializationHandlesNumericValuesWithDatatypes() throws Exception {
891893
assertEquals(BigInteger.valueOf(128000), result.getBigIntegerValue());
892894
assertEquals(BigDecimal.valueOf(128000.821), result.getBigDecimalValue());
893895
}
896+
897+
/**
898+
* Bug #84
899+
*/
900+
@Test
901+
void deserializationHandlesTypedLiteralsForTypedProperties() throws Exception {
902+
final JsonArray input = readAndExpand("objectWithTypedLiteralInProperties.json");
903+
final PersonWithTypedProperties result = sut.deserialize(input, PersonWithTypedProperties.class);
904+
assertNotNull(result);
905+
assertEquals("Catherine", result.getFirstName());
906+
assertEquals("Halsey", result.getLastName());
907+
assertThat(result.getProperties(),
908+
hasKey(URI.create("http://onto.fel.cvut.cz/ontologies/application/jb4jsonld/attribute/warrantor")));
909+
assertEquals(Set.of("Lord Hood"), result.getProperties().get(URI.create(
910+
"http://onto.fel.cvut.cz/ontologies/application/jb4jsonld/attribute/warrantor")));
911+
assertThat(result.getProperties(), hasKey(URI.create(
912+
"http://onto.fel.cvut.cz/ontologies/application/jb4jsonld/attribute/revision-count")));
913+
assertEquals(Set.of(4, 8), result.getProperties().get(URI.create(
914+
"http://onto.fel.cvut.cz/ontologies/application/jb4jsonld/attribute/revision-count")));
915+
assertThat(result.getProperties(),
916+
hasKey(URI.create("http://onto.fel.cvut.cz/ontologies/application/jb4jsonld/attribute/approved")));
917+
assertEquals(Set.of(true), result.getProperties().get(URI.create(
918+
"http://onto.fel.cvut.cz/ontologies/application/jb4jsonld/attribute/approved")));
919+
}
920+
921+
@Test
922+
void deserializationHandlesTypedLiteralsForUntypedProperties() throws Exception {
923+
final JsonArray input = readAndExpand("objectWithTypedLiteralInProperties.json");
924+
final Person result = sut.deserialize(input, Person.class);
925+
assertNotNull(result);
926+
assertEquals("Catherine", result.getFirstName());
927+
assertEquals("Halsey", result.getLastName());
928+
assertThat(result.getProperties(),
929+
hasKey("http://onto.fel.cvut.cz/ontologies/application/jb4jsonld/attribute/warrantor"));
930+
assertEquals(Set.of("Lord Hood"), result.getProperties()
931+
.get("http://onto.fel.cvut.cz/ontologies/application/jb4jsonld/attribute/warrantor"));
932+
assertThat(result.getProperties(),
933+
hasKey("http://onto.fel.cvut.cz/ontologies/application/jb4jsonld/attribute/revision-count"));
934+
assertEquals(Set.of("4", "8"), result.getProperties()
935+
.get("http://onto.fel.cvut.cz/ontologies/application/jb4jsonld/attribute/revision-count"));
936+
assertThat(result.getProperties(),
937+
hasKey("http://onto.fel.cvut.cz/ontologies/application/jb4jsonld/attribute/approved"));
938+
assertEquals(Set.of("true"), result.getProperties()
939+
.get("http://onto.fel.cvut.cz/ontologies/application/jb4jsonld/attribute/approved"));
940+
}
894941
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"@context": {
3+
"firstName": "http://xmlns.com/foaf/0.1/firstName",
4+
"lastName": "http://xmlns.com/foaf/0.1/lastName",
5+
"types": "@type",
6+
"iri": "@id"
7+
},
8+
"iri": "http://krizik.felk.cvut.cz/ontologies/jb4jsonld#Catherine+Halsey",
9+
"types": [
10+
"http://onto.fel.cvut.cz/ontologies/ufo/Person",
11+
"http://krizik.felk.cvut.cz/ontologies/jb4jsonld/Employee",
12+
"http://krizik.felk.cvut.cz/ontologies/jb4jsonld/User"
13+
],
14+
"firstName": "Catherine",
15+
"lastName": "Halsey",
16+
"http://onto.fel.cvut.cz/ontologies/application/jb4jsonld/attribute/warrantor": [
17+
"Lord Hood"
18+
],
19+
"http://onto.fel.cvut.cz/ontologies/application/jb4jsonld/attribute/revision-count": [
20+
{
21+
"types": "http://www.w3.org/2001/XMLSchema#int",
22+
"@value": 4
23+
},
24+
{
25+
"types": "http://www.w3.org/2001/XMLSchema#int",
26+
"@value": 8
27+
}
28+
],
29+
"http://onto.fel.cvut.cz/ontologies/application/jb4jsonld/attribute/approved": [
30+
true
31+
]
32+
}

0 commit comments

Comments
 (0)