Skip to content

Commit

Permalink
Merge pull request #1 from protegeproject/WHO-setup
Browse files Browse the repository at this point in the history
added owl annotation value deserializer
  • Loading branch information
alexsilaghi authored Jul 3, 2024
2 parents 6ac6fb3 + 100860a commit 241df37
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</parent>
<groupId>edu.stanford.protege</groupId>
<artifactId>webprotege-jackson</artifactId>
<version>0.9.2</version>
<version>0.9.3</version>
<name>webprotege-jackson</name>
<description>Jackson Serializers and Deserializers for OWL API Objects</description>
<properties>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package edu.stanford.protege.webprotege.jackson;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
import org.semanticweb.owlapi.model.IRI;

import java.io.IOException;

/**
* Matthew Horridge
* Stanford Center for Biomedical Informatics Research
* 18 Jun 2018
*/
public class IriDeserializer extends StdDeserializer<IRI> {

public IriDeserializer() {
super(IRI.class);
}

@Override
public IRI deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
return IRI.create(jsonParser.getValueAsString());
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package edu.stanford.protege.webprotege.jackson;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
import edu.stanford.protege.webprotege.jackson.OWLLiteralDeserializer;
import org.semanticweb.owlapi.model.OWLAnnotationValue;

import javax.annotation.Nonnull;
import javax.inject.Inject;
import java.io.IOException;

import static com.google.common.base.Preconditions.checkNotNull;

public class OWLAnnotationValueDeserializer extends StdDeserializer<OWLAnnotationValue> {

@Nonnull
private final OWLLiteralDeserializer literalDeserializer;

@Nonnull
private final IriDeserializer iriDeserializer;

@Inject
public OWLAnnotationValueDeserializer(@Nonnull OWLLiteralDeserializer literalDeserializer, @Nonnull IriDeserializer iriDeserializer) {
super(OWLAnnotationValue.class);
this.literalDeserializer = checkNotNull(literalDeserializer);
this.iriDeserializer = checkNotNull(iriDeserializer);
}

@Override
public OWLAnnotationValue deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
if(p.hasToken(JsonToken.START_OBJECT)) {
return literalDeserializer.deserialize(p, ctxt);
}
else {
return iriDeserializer.deserialize(p, ctxt);
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ public ObjectMapper objectMapper(OWLDataFactory dataFactory) {
module.setMixInAnnotation(OWLAnnotationProperty.class, OWLAnnotationPropertyMixin.class);
module.addDeserializer(OWLAnnotationPropertyImpl.class, new OWLEntityDeserializer<>(dataFactory, EntityType.ANNOTATION_PROPERTY));

module.addDeserializer(OWLAnnotationValue.class, new OWLAnnotationValueDeserializer(new OWLLiteralDeserializer(dataFactory), new IriDeserializer()));

module.setMixInAnnotation(OWLIndividual.class, OWLIndividualMixin.class);

module.setMixInAnnotation(OWLNamedIndividual.class, OWLNamedIndividualMixin.class);
Expand Down

0 comments on commit 241df37

Please sign in to comment.