Fixes Issue 0024853: data not shown when location city field is blank.
authorShankar Balachandran <shankar.balachandran@openbravo.com>
Tue, 01 Oct 2013 12:15:58 +0530
changeset 21223 41199a2bd66a
parent 21222 4f2785012d36
child 21224 541c707a5e9b
Fixes Issue 0024853: data not shown when location city field is blank.

When the display property field value is null, exception was thrown.
Handled the exception and set value only if it is not null.
modules/org.openbravo.service.json/src/org/openbravo/service/json/DataToJsonConverter.java
--- a/modules/org.openbravo.service.json/src/org/openbravo/service/json/DataToJsonConverter.java	Mon Sep 30 21:37:06 2013 +0200
+++ b/modules/org.openbravo.service.json/src/org/openbravo/service/json/DataToJsonConverter.java	Tue Oct 01 12:15:58 2013 +0530
@@ -243,6 +243,7 @@
 
   private void addBaseOBObject(JSONObject jsonObject, Property referencingProperty,
       String propertyName, Property referencedProperty, BaseOBObject obObject) throws JSONException {
+    String identifier = null;
     // jsonObject.put(propertyName, toJsonObject(obObject, DataResolvingMode.SHORT));
     if (referencedProperty != null) {
       try {
@@ -268,8 +269,9 @@
       // statements. The values will be automatically translated if
       // getIdentifier() is called.
       if (referencingProperty.hasDisplayColumn()) {
-        String identifier = obObject.get(referencingProperty.getDisplayPropertyName(),
-            OBContext.getOBContext().getLanguage(), (String) obObject.getId()).toString();
+        Object referenceObject = obObject.get(referencingProperty.getDisplayPropertyName(),
+            OBContext.getOBContext().getLanguage(), (String) obObject.getId());
+        identifier = referenceObject != null ? referenceObject.toString() : "";
         if (referencingProperty.isDisplayValue()) {
           if (obObject.getEntity().hasProperty("searchKey")) {
             String value = obObject.get("searchKey", OBContext.getOBContext().getLanguage(),
@@ -290,11 +292,11 @@
             + DalUtil.FIELDSEPARATOR + JsonConstants.IDENTIFIER, ((BaseOBObject) obObject
             .get(referencingProperty.getDisplayPropertyName())).getIdentifier());
       } else {
-        jsonObject.put(
-            propertyName.replace(DalUtil.DOT, DalUtil.FIELDSEPARATOR) + DalUtil.FIELDSEPARATOR
-                + JsonConstants.IDENTIFIER,
-            obObject.get(referencingProperty.getDisplayPropertyName(),
-                OBContext.getOBContext().getLanguage(), (String) obObject.getId()).toString());
+        Object referenceObject = obObject.get(referencingProperty.getDisplayPropertyName(),
+            OBContext.getOBContext().getLanguage(), (String) obObject.getId());
+        identifier = referenceObject != null ? referenceObject.toString() : "";
+        jsonObject.put(propertyName.replace(DalUtil.DOT, DalUtil.FIELDSEPARATOR)
+            + DalUtil.FIELDSEPARATOR + JsonConstants.IDENTIFIER, identifier);
       }
     } else {
       jsonObject.put(propertyName.replace(DalUtil.DOT, DalUtil.FIELDSEPARATOR)