# HG changeset patch # User Omair Majid # Date 1392845976 18000 # Node ID 28252d3475bd769e4ef8bb2fee329d014847b46a # Parent 5877be030593aefec7fe3d9cd4d04fb2b3e58f43 Don't generate empty `commands` and `extensions` elements diff -r 5877be030593 -r 28252d3475bd com.redhat.thermostat.tools.eclipse.plugin/src/com/redhat/thermostat/tools/eclipse/plugin/model/Plugin.java --- a/com.redhat.thermostat.tools.eclipse.plugin/src/com/redhat/thermostat/tools/eclipse/plugin/model/Plugin.java Fri Feb 07 16:11:46 2014 -0500 +++ b/com.redhat.thermostat.tools.eclipse.plugin/src/com/redhat/thermostat/tools/eclipse/plugin/model/Plugin.java Wed Feb 19 16:39:36 2014 -0500 @@ -3,6 +3,8 @@ import java.util.ArrayList; import java.util.List; +import javax.xml.bind.Marshaller; +import javax.xml.bind.Unmarshaller; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlElement; @@ -100,4 +102,26 @@ } } + // JAXB-specific hooks + // try and pretty up the resulting xml file to create no empty lists + + /** Turn empty list into no-element when marshalling to xml */ + void beforeMarshal(Marshaller marshaller) { + if (this.commands == null || this.commands.isEmpty()) { + this.commands = null; + } + if (this.extensions == null || this.extensions.isEmpty()) { + this.extensions = null; + } + } + + /** If null elements were read, re-initialize to empty list */ + void afterUnmarshal(Unmarshaller unmarshaller, Object parent) { + if (this.commands == null) { + this.commands = new ArrayList<>(); + } + if (this.extensions == null) { + this.extensions = new ArrayList<>(); + } + } }