From c093881f544c247c45587aab9b34df56f32c0de2 Mon Sep 17 00:00:00 2001 From: macdonst Date: Fri, 22 Jul 2011 03:10:41 +0800 Subject: [PATCH] Issue #174: contact attribs should return null instead of empty array Currently the implementation will return an empty array for the following Contact attributes: phoneNumbers, emails, addresses, ims, organizations, addresses, websites and photos. With this fix these attributes will be null unless the lenght of the array is greater than 0. --- .../src/com/phonegap/ContactAccessorSdk5.java | 29 ++++++++++++++----- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/framework/src/com/phonegap/ContactAccessorSdk5.java b/framework/src/com/phonegap/ContactAccessorSdk5.java index bcb25227..7e856049 100644 --- a/framework/src/com/phonegap/ContactAccessorSdk5.java +++ b/framework/src/com/phonegap/ContactAccessorSdk5.java @@ -425,13 +425,28 @@ public class ContactAccessorSdk5 extends ContactAccessor { JSONArray addresses, JSONArray phones, JSONArray emails, JSONArray ims, JSONArray websites, JSONArray photos) { try { - contact.put("organizations", organizations); - contact.put("addresses", addresses); - contact.put("phoneNumbers", phones); - contact.put("emails", emails); - contact.put("ims", ims); - contact.put("websites", websites); - contact.put("photos", photos); + // Only return the array if it has at least one entry + if (organizations.length() > 0) { + contact.put("organizations", organizations); + } + if (addresses.length() > 0) { + contact.put("addresses", addresses); + } + if (phones.length() > 0) { + contact.put("phoneNumbers", phones); + } + if (emails.length() > 0) { + contact.put("emails", emails); + } + if (ims.length() > 0) { + contact.put("ims", ims); + } + if (websites.length() > 0) { + contact.put("websites", websites); + } + if (photos.length() > 0) { + contact.put("photos", photos); + } } catch (JSONException e) { Log.e(LOG_TAG,e.getMessage(),e);