kbss-cvut / jb4jsonld

JSON-LD serialization and deserialization for Java REST services.
GNU Lesser General Public License v3.0
10 stars 3 forks source link

deserializing subclass defined in external maven artifact #35

Closed cristianolongoodhl closed 3 years ago

cristianolongoodhl commented 3 years ago

I have the following hierarchy of @OWLClasses

}

@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` 
cristianolongoodhl commented 3 years ago

Note that the project is based on spring boot

cristianolongoodhl commented 3 years ago

further investigation in needed