Description
As discussed on the mailinglist ([1]), adding type-safety to property retrieval in org.hippoecm.hst.content.beans.standard.HippoItem would make a nice addition to the core. In this specific case, for a multi-value String property in Hippo (thus String[]), the JCRValueProvider infers a simple String (no String[]!) when only 1 value with the blank String ("") is present in the propertyvalues.
This can be avoided by providing a defaultValue, but then again... the same method simply casts the actual value to the same type of defaultValue. This of course also throws a ClassCastException in the described case. It would me much cleaner if an actual typecheck is performed or assignability check is performed.
In my project I've overriden this API-method in my BaseDocument, to introduce type checking. Using this implementation, I no longer get the CCE's and both JCR+Hippo behave as expected:
@Override
public <T> T getProperty(String name, T defaultValue) {
Object value = getProperty(name);
if(value == null)
else
{ Class valueClass = value.getClass(); Class defaultClass = defaultValue.getClass(); return (defaultClass.isAssignableFrom(valueClass) ? (T) value : defaultValue); }}
I can provide a patch against 7.8.8. if that's desired. I've also seen this has not been fixed in 7.9., so I can also provide a patch against 7.9. Please let me know whether my description above is satisfactory, or whether a patch is desired (don't forget to mention the version to patch against ).
Regards,
Brian
[1] https://groups.google.com/forum/#!topic/hippo-community/1dIqNi9boDk