Skip to content

Commit

Permalink
Update PropertyGroup.getProperties to omit properties with null values
Browse files Browse the repository at this point in the history
Now that convertJsonValue can return null, this is safer/easier than
updating all the callers to be able to handle null.

Signed-off-by: Lee Surprenant <lmsurpre@us.ibm.com>
  • Loading branch information
lmsurpre committed Oct 4, 2021
1 parent 2d82cc6 commit 37fb951
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -237,12 +237,16 @@ public Object[] getArrayProperty(String propertyName) throws Exception {
/**
* Returns the properties contained in the PropertyGroup in the form of a list of
* PropertyEntry instances. If no properties exist, then an empty list will be returned.
* Properties with a value of null will be omitted from the list.
* @throws Exception
*/
public List<PropertyEntry> getProperties() throws Exception {
List<PropertyEntry> results = new ArrayList<>();
for (Map.Entry<String, JsonValue> entry : jsonObj.entrySet()) {
results.add(new PropertyEntry(entry.getKey(), convertJsonValue(entry.getValue())));
Object jsonValue = convertJsonValue(entry.getValue());
if (jsonValue != null) {
results.add(new PropertyEntry(entry.getKey(), convertJsonValue(entry.getValue())));
}
}
return results;
}
Expand Down

0 comments on commit 37fb951

Please sign in to comment.