diff --git a/openerp-client/pom.xml b/openerp-client/pom.xml
index 52c08d1..26c3f31 100644
--- a/openerp-client/pom.xml
+++ b/openerp-client/pom.xml
@@ -221,6 +221,11 @@
mockito-core
test
+
+ org.apache.commons
+ commons-lang3
+ 3.12.0
+
openerp-client
diff --git a/openerp-client/src/main/java/org/bahmni/openerp/web/request/builder/RequestBuilder.java b/openerp-client/src/main/java/org/bahmni/openerp/web/request/builder/RequestBuilder.java
index c16d955..9052957 100644
--- a/openerp-client/src/main/java/org/bahmni/openerp/web/request/builder/RequestBuilder.java
+++ b/openerp-client/src/main/java/org/bahmni/openerp/web/request/builder/RequestBuilder.java
@@ -3,6 +3,7 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import freemarker.template.Template;
+import org.apache.commons.lang3.math.NumberUtils;
import org.bahmni.openerp.web.OpenERPException;
import org.bahmni.openerp.web.config.FreeMarkerConfig;
import org.bahmni.openerp.web.request.OpenERPRequest;
@@ -53,10 +54,21 @@ private static HashMap getParameters(OpenERPRequest openERPReque
}
private static Object parseParameterValue(String value) {
- try {
- ObjectMapper mapper = new ObjectMapper();
- return mapper.readValue(value, Object.class);
- } catch (Exception e) {
+ if (value.startsWith("{") && value.endsWith("}")) {
+ try {
+ ObjectMapper mapper = new ObjectMapper();
+ return mapper.readValue(value, Object.class);
+ } catch (Exception e) {
+ return value;
+ }
+ } else {
+ if(NumberUtils.isCreatable(value)){
+ try {
+ return NumberUtils.createNumber(value);
+ } catch (Exception e) {
+ return value;
+ }
+ }
return value;
}
}
diff --git a/openerp-client/src/test/java/org/bahmni/openerp/web/request/builder/RequestBuilderTest.java b/openerp-client/src/test/java/org/bahmni/openerp/web/request/builder/RequestBuilderTest.java
index b591ea4..50b06e6 100644
--- a/openerp-client/src/test/java/org/bahmni/openerp/web/request/builder/RequestBuilderTest.java
+++ b/openerp-client/src/test/java/org/bahmni/openerp/web/request/builder/RequestBuilderTest.java
@@ -1,14 +1,10 @@
package org.bahmni.openerp.web.request.builder;
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
import org.bahmni.openerp.web.request.OpenERPRequest;
import org.junit.Test;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.List;
-import java.util.UUID;
import static org.junit.Assert.assertEquals;
@@ -227,6 +223,54 @@ public void shouldEscapeHindiCharactersWhenRESTRequestIsCreated() throws Excepti
comparingStringWithoutSpaces(requestXml, expected);
}
+ @Test
+ public void shouldReturnStringEvenWhenRESTRequestStartsWithANumber() throws Exception {
+
+ String name = "6 - DENTAL - Surgical Extraction of tooth including LA - 1200 - D";
+ String expected = "{\"name\":\"6 - DENTAL - Surgical Extraction of tooth including LA - 1200 - D\"}";
+
+ Parameter parameter = new Parameter("name", name, "string");
+ ArrayList parameters = new ArrayList();
+ parameters.add(parameter);
+ OpenERPRequest request = new OpenERPRequest("res.partner", "execute", parameters);
+
+ String requestXml = RequestBuilder.buildNewRestRequest(request);
+
+ comparingStringWithoutSpaces(requestXml, expected);
+ }
+
+ @Test
+ public void shouldReturnNumberWhenRESTRequestIsANumber() throws Exception {
+
+ String number = "62380";
+ String expected = "{\"number\":62380}";
+
+ Parameter parameter = new Parameter("number", number, "string");
+ ArrayList parameters = new ArrayList();
+ parameters.add(parameter);
+ OpenERPRequest request = new OpenERPRequest("res.partner", "execute", parameters);
+
+ String requestXml = RequestBuilder.buildNewRestRequest(request);
+
+ comparingStringWithoutSpaces(requestXml, expected);
+ }
+
+ @Test
+ public void shouldReturnNumberWhenRESTRequestIsADecimal() throws Exception {
+
+ String number = "62380.9";
+ String expected = "{\"number\":62380.9}";
+
+ Parameter parameter = new Parameter("number", number, "string");
+ ArrayList parameters = new ArrayList();
+ parameters.add(parameter);
+ OpenERPRequest request = new OpenERPRequest("res.partner", "execute", parameters);
+
+ String requestXml = RequestBuilder.buildNewRestRequest(request);
+
+ comparingStringWithoutSpaces(requestXml, expected);
+ }
+
private void comparingStringWithoutSpaces(String requestXml, String expected) {
assertEquals(expected.replaceAll("\\s{2,}", ""), requestXml.replaceAll("\\s{2,}", "").trim());
}