@OWLClass(iri = "http://www.example.org/parent")
public class ParentClass implements Serializable {
@Id
protected String id;
public void setId(final String id) {
this.id = id;
}
public String getId() {
return id;
}
}
and two empty child classes
@OWLClass(iri = "http://www.example.org/childa")
public class ChildClassA extends ParentClass implements Serializable {
}
@OWLClass(iri = "http://www.example.org/childb")
public class ChildClassB extends ParentClass implements Serializable {
}
When deserializing an object of class `ChildClassA` but using a reader for `ParentClass`, the deserializer correctly return on object of class `ChildClassA`. Here follows the test
@Test
public void shouldDeserializationReturnMostSpecificSubclass() throws JsonProcessingException {
final ChildClassA a = new ChildClassA();
a.setId("http://example.com/childa/a");
final String serialized = "{\"@id\":\"http://example.com/childa/a\",\"@type\":[\"http://www.example.org/childa\",\"http://www.example.org/parent\",\"http://www.example.org/grandparent\"]}";
final ObjectReader r = jsonLdObjectMapper().readerFor(ParentClass.class);
final ParentClass deserialized = r.readValue(serialized);
assertEquals(a.getId(), deserialized.getId());
assertTrue(deserialized instanceof ChildClassA);
}
The project is compiled with maven and tests is run by the maven surefire plugin. However, I decided to pack the class hiararchy above in a standalone maven artifact, and import the same artifact in another maven project by declaring it as dependency. The same test above, moved in this project which does not contains the hierarchy sources but just include it as dependency, fails because the deserializer returns an object of class `ParentClass`
I have the following hierarchy of
@OWLClass
esa parent class with just
@id
}
@OWLClass(iri = "http://www.example.org/childb") public class ChildClassB extends ParentClass implements Serializable {
}