Skip to content

Commit 9656ea7

Browse files
committed
feat: add getIdProperty method to retrieve a nested id property value as String
1 parent f4046ea commit 9656ea7

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/main/java/edu/kit/datamanager/ro_crate/entities/AbstractEntity.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,21 @@ public JsonNode getProperty(String propertyKey) {
112112
return this.properties.get(propertyKey);
113113
}
114114

115+
/**
116+
* Returns the value of the property with the given key as a String.
117+
* If the property is not found, it returns null.
118+
*
119+
* @param propertyKey the key of the property.
120+
* @return the value of the property as a String or null if not found.
121+
*/
122+
public String getIdProperty(String propertyKey) {
123+
JsonNode node = this.properties.get(propertyKey);
124+
if (node != null) {
125+
return node.path("@id").asText(null);
126+
}
127+
return null;
128+
}
129+
115130
@JsonIgnore
116131
public String getId() {
117132
JsonNode id = this.properties.get("@id");

0 commit comments

Comments
 (0)