I want to extend the managed object with some custom fragments. Something like this:
@Alias(value = "Dictionary")
public class Dictionary extends AbstractDynamicProperties {
private Map<String, String> records = new HashMap<>();
@JSONProperty(ignoreIfNull = false)
public Map<String, String> getRecords() { return this.records; }
(...)
}
When I create a new managed object and save it into the inventory API everything looks great:
ManagedObjectRepresentation dictionary = new ManagedObjectRepresentation();
dictionary.setName(dictionaryName);
dictionary.set(new Dictionary());
Unfortunately, when I fetch this managed object and want to retrieve the Dictionary class I receive a HashMap:
dictionary.get(Dictionary.class).addRecord(key, value);
After some debugging, I founded that when a managed object is saved, ExtensibilityConverter (tryGetAlias() line 98) is iterating over all annotation in the object and if it finds the Alias annotation, it takes the value from there.
On the other hand, when the response from the Cumulocity is being deserialized, Svenson is using AliasMapClassFinder and I can see only initialization in the ExtensibilityConverter. I can't spot any place that this map alias2ClassName is filled and because it's always empty I receive the HashMap instead of the class I expect.
Am I missing something? Or this is a bug in the SDK?