-
Notifications
You must be signed in to change notification settings - Fork 57
Closed
Milestone
Description
Store type hints in documents when they are persisted to the DB (if the property type and actual type do not match).
Example:
public interface Person {
String getName();
}
public class Employee implements Person {
private String name;
public void setName(String name) {
this.name = name;
}
@Override
public String getName() {
return name;
}
}
public class Company {
@Key
private String key;
private Person manager;
public String getKey() {
return key;
}
public Person getManager() {
return manager;
}
public void setManager(Person manager) {
this.manager = manager;
}
}
Employee manager = new Employee();
manager.setName("Jon Doe");
Company comp = new Company();
comp.setManager(manager);
arangoOperations.insert(comp);
arangoOps.find(comp.getKey(), Company.class);This throws an exception because interface Person can not be instantiated. To fix this problem we need to store an additional property (e.g. _type) with the name of the class:
{
"manager": {
"_type": "package.Employee"
"name": "Jon Doe"
}
}
First, a org.springframework.data.convert.TypeMapper must be implemented that reads and writes the type information. Then the DefaultArangoConverter needs to write the type hints if the property type and the actual type do not match (here Person and Employee). If an object is read and has a type hint, then this class must be used.
I will have a look at this at the weekend.
Metadata
Metadata
Assignees
Labels
No labels