Added null check for empty ArrayNode object in DhcpRelayWebResource.java
Change-Id: Iace1230e73ca44a6a0591de9c3d843bbc96743f9
(cherry picked from commit 4ae2b6f047da2facbd8be06cf2b1971c1381ec8b)
diff --git a/apps/dhcprelay/web/src/main/java/org/onosproject/dhcprelay/rest/DhcpRelayWebResource.java b/apps/dhcprelay/web/src/main/java/org/onosproject/dhcprelay/rest/DhcpRelayWebResource.java
index d5e142a..bf19691 100644
--- a/apps/dhcprelay/web/src/main/java/org/onosproject/dhcprelay/rest/DhcpRelayWebResource.java
+++ b/apps/dhcprelay/web/src/main/java/org/onosproject/dhcprelay/rest/DhcpRelayWebResource.java
@@ -163,9 +163,15 @@
*/
private ObjectNode getDhcpRelayServersJsonOutput() {
ObjectNode node = mapper().createObjectNode();
- node.put("Default-DHCP-Servers", getDefaultDhcpServers());
- node.put("Indirect-DHCP-Servers", getIndirectDhcpServers());
- node.put("DHCP-Relay-Records([D]:Directly-Connected)", dhcpRelayRecords());
+ if (getDefaultDhcpServers().size() != 0) {
+ node.put("Default-DHCP-Servers", getDefaultDhcpServers());
+ }
+ if (getIndirectDhcpServers().size() != 0) {
+ node.put("Indirect-DHCP-Servers", getIndirectDhcpServers());
+ }
+ if (dhcpRelayRecords().size() != 0) {
+ node.put("DHCP-Relay-Records", dhcpRelayRecords());
+ }
return node;
}