diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/vcardtemp/packet/VCard.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/vcardtemp/packet/VCard.java index 303510031..fd18638e4 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/vcardtemp/packet/VCard.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/vcardtemp/packet/VCard.java @@ -565,23 +565,27 @@ public class VCard extends IQ { xml.rightAngleBracket(); if (hasNameField()) { xml.openElement("N"); - xml.element("FAMILY", lastName); - xml.element("GIVEN", firstName); - xml.element("MIDDLE", middleName); + xml.optElement("FAMILY", lastName); + xml.optElement("GIVEN", firstName); + xml.optElement("MIDDLE", middleName); xml.closeElement("N"); } if (hasOrganizationFields()) { xml.openElement("ORG"); - xml.element("ORGNAME", organization); - xml.element("ORGUNIT", organizationUnit); + xml.optElement("ORGNAME", organization); + xml.optElement("ORGUNIT", organizationUnit); xml.closeElement("ORG"); } for (Entry entry : otherSimpleFields.entrySet()) { - xml.element(entry.getKey(), entry.getValue()); + xml.optElement(entry.getKey(), entry.getValue()); } for (Entry entry : otherUnescapableFields.entrySet()) { + final String value = entry.getValue(); + if (value == null) { + continue; + } xml.openElement(entry.getKey()); - xml.append(entry.getValue()); + xml.append(value); xml.closeElement(entry.getKey()); } if (photoBinval != null) { @@ -607,24 +611,36 @@ public class VCard extends IQ { xml.closeElement("EMAIL"); } for (Entry phone : workPhones.entrySet()) { + final String number = phone.getValue(); + if (number == null) { + continue; + } xml.openElement("TEL"); xml.emptyElement("WORK"); xml.emptyElement(phone.getKey()); - xml.element("NUMBER", phone.getValue()); + xml.element("NUMBER", number); xml.closeElement("TEL"); } for (Entry phone : homePhones.entrySet()) { + final String number = phone.getValue(); + if (number == null) { + continue; + } xml.openElement("TEL"); xml.emptyElement("HOME"); xml.emptyElement(phone.getKey()); - xml.element("NUMBER", phone.getValue()); + xml.element("NUMBER", number); xml.closeElement("TEL"); } if (!workAddr.isEmpty()) { xml.openElement("ADR"); xml.emptyElement("WORK"); for (Entry entry : workAddr.entrySet()) { - xml.element(entry.getKey(), entry.getValue()); + final String value = entry.getValue(); + if (value == null) { + continue; + } + xml.element(entry.getKey(), value); } xml.closeElement("ADR"); } @@ -632,7 +648,11 @@ public class VCard extends IQ { xml.openElement("ADR"); xml.emptyElement("HOME"); for (Entry entry : homeAddr.entrySet()) { - xml.element(entry.getKey(), entry.getValue()); + final String value = entry.getValue(); + if (value == null) { + continue; + } + xml.element(entry.getKey(), value); } xml.closeElement("ADR"); }