Wish I knew about that before! Thanks heaps for the reference.
Gonna put my function here for any future references too. Feel free to point out any improvements.
public Map<PropertyIdentifier, Encodable> getObjectPropertyListNotNull(RemoteDevice d, ObjectIdentifier obj) throws BACnetException{
List<ObjectPropertyTypeDefinition> propsDefs = ObjectProperties.getObjectPropertyTypeDefinitions(obj.getObjectType());
ArrayList<PropertyIdentifier> props = new ArrayList<PropertyIdentifier>(propsDefs.size());
Map<PropertyIdentifier, Encodable> propValuesFinal = new HashMap<>();
for(ObjectPropertyTypeDefinition prop : propsDefs){props.add(prop.getPropertyTypeDefinition().getPropertyIdentifier());}
if(d.getObject(obj) == null){
Map<PropertyIdentifier, Encodable> propValues = RequestUtils.getProperties(localDevice, d, obj, null, props.toArray(new PropertyIdentifier[props.size()]));
propValues.forEach((pid, val) -> {
if(val instanceof ErrorClassAndCode)
return;
propValuesFinal.put(pid, val);
d.setObjectProperty(obj, pid, val);
});
}
else{
for(PropertyIdentifier pid : props){
Encodable val = d.getObject(obj).getProperty(pid);
if(val != null){
propValuesFinal.put(pid, val);
}
}
}
return propValuesFinal;
}