Environment (Required on creation):
- Camunda 7.15.3-ee
Description (Required on creation; please attach any relevant screenshots, stacktraces, log files, etc. to the ticket):
When dealing with bigger floating-point numbers, using Spin's "jsonPath" method on a JSON object leads to unexpected rounding behavior.
Steps to reproduce (Required on creation):
Sample test case is attached for reference:
- Create a Script Task ("javascript" format) reading floating point JSON property via Spin's "jsonPath" method, for example:
var response2 = execution.getVariable("response") var query = "$.value" S(response2).jsonPath(query).numberValue()
- Start an instance with a variable of type String which contains a JSON. The JSON should contain a numeric property as shown below.
Map<String, Object> variables = new HashMap<>(); String var = "{\"id\":\"testid\",\"value\":\"234302.13\"}"; variables.put("response", var); runtimeService.startProcessInstanceByKey("sample1", variables);
Observed Behavior (Required on creation):
The value returned by jsonPath.numberValue() is 234302.12 instead of 234302.13
Expected behavior (Required on creation):
The value returned by jsonPath.numberValue() should match the numeric value of property in JSON i.e. 234302.13
Root Cause (Required on prioritization):
JacksonJsonPathQuery is returned by S(response).jsonPath(query) method. If the input parameter is an instance of Number, we create a JSON node with a Float value. Here is the code for reference: https://github.com/camunda/camunda-spin/blob/b2d72eb8a83887d78009011d17667d0c73542b99/dataformat-json-jackson/src/main/java/org/camunda/spin/impl/json/jackson/format/JacksonJsonDataFormat.java#L238
Solution Ideas (Optional):
Create Double nodes in case of abstract Number nodes. This is also consistent with how Jackson operates by default when using our "prop" methods.
Hints (Optional):
This is the controller panel for Smart Panels app
[CAM-13868] Spin jsonPath method uses Float as default data type for Number node
Link | New: This issue is related to SUPPORT-11544 [ SUPPORT-11544 ] |
Component/s | New: spin [ 12350 ] | |
Description |
Original:
*Steps to reproduce*
Sample test case is attached for reference: # Install Camunda 7.15.3-ee # Create a simple BPMN that contains a script task (javascript format). Inside a script task, read Json property of type numeric via jsonPath. {code} var response2 = execution.getVariable("response") var query = "$.value" S(response2).jsonPath(query).numberValue() {code} # Start process instance with a variable of type String which contains a json. The JSON should contain a numeric property as shown below. {code:java} Map<String, Object> variables = new HashMap<>(); String var = "{\"id\":\"testid\",\"value\":\"234302.13\"}"; variables.put("response", var); ProcessInstance processInstance = processEngineRule.getRuntimeService().createProcessInstanceByKey("sample1") .setVariables(variables).execute(); {code} *Observed behaviour* # The value returned by jsonPath.numberValue() is {{234302.12}} instead of {{234302.13}} *Expected behaviour* # The value returned by jsonPath.numberValue() should match the numeric value of property in JSON i.e. {{234302.13}} *Hints* [JacksonJsonPathQuery|https://github.com/camunda/camunda-spin/blob/master/dataformat-json-jackson/src/main/java/org/camunda/spin/impl/json/jackson/query/JacksonJsonPathQuery.java] is returned by {{S(response).jsonPath(query)}} method. And if input parameter is instanceof Number, then we createJsonNode with Float value. Here is the code for reference: https://github.com/camunda/camunda-spin/blob/b2d72eb8a83887d78009011d17667d0c73542b99/dataformat-json-jackson/src/main/java/org/camunda/spin/impl/json/jackson/format/JacksonJsonDataFormat.java#L238 |
New:
h4. Environment (Required on creation):
* Camunda 7.15.3-ee h4. Description (Required on creation; please attach any relevant screenshots, stacktraces, log files, etc. to the ticket): When dealing with bigger floating-point numbers, using Spin's "jsonPath" method on a JSON object leads to unexpected rounding behavior. h4. Steps to reproduce (Required on creation): Sample test case is attached for reference: # Create a Script Task ("javascript" format) reading floating point JSON property via Spin's "jsonPath" method, for example: {code:java} var response2 = execution.getVariable("response") var query = "$.value" S(response2).jsonPath(query).numberValue() {code} # Start an instance with a variable of type String which contains a JSON. The JSON should contain a numeric property as shown below. {code:java} Map<String, Object> variables = new HashMap<>(); String var = "{\"id\":\"testid\",\"value\":\"234302.13\"}"; variables.put("response", var); runtimeService.startProcessInstanceByKey("sample1", variables); {code} h4. Observed Behavior (Required on creation): The value returned by jsonPath.numberValue() is {{234302.12}} instead of {{234302.13}} h4. Expected behavior (Required on creation): The value returned by jsonPath.numberValue() should match the numeric value of property in JSON i.e. {{234302.13}} h4. Root Cause (Required on prioritization): [JacksonJsonPathQuery|https://github.com/camunda/camunda-spin/blob/master/dataformat-json-jackson/src/main/java/org/camunda/spin/impl/json/jackson/query/JacksonJsonPathQuery.java] is returned by {{S(response).jsonPath(query)}} method. If the input parameter is an instance of {{Number}}, we create a JSON node with a {{Float}} value. Here is the code for reference: [https://github.com/camunda/camunda-spin/blob/b2d72eb8a83887d78009011d17667d0c73542b99/dataformat-json-jackson/src/main/java/org/camunda/spin/impl/json/jackson/format/JacksonJsonDataFormat.java#L238] h4. Solution Ideas (Optional): Create {{Double}} nodes in case of abstract Number nodes. This is also consistent with how Jackson operates by default when using our "prop" methods. h4. Hints (Optional): |