-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from protegeproject/WHO-setup
added owl annotation value deserializer
- Loading branch information
Showing
4 changed files
with
71 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/main/java/edu/stanford/protege/webprotege/jackson/IriDeserializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} | ||
|
42 changes: 42 additions & 0 deletions
42
src/main/java/edu/stanford/protege/webprotege/jackson/OWLAnnotationValueDeserializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters