Description I invoke a simple DMI request which returns double values of varying precision. I view the types of the results on the client side.
Actual results Those with 14 or 15 decimal places are Strings when viewed on the client side. The rest are doubles.
Expected results All values should show up on the client side as doubles, not Strings.
NOTE I ran this in GWT development mode
Screen shot of actual results:
SmartClient Version: v10.1p_2016-01-14/Enterprise Deployment (built 2016-01-14)
Chrome browser, Version 48.0.2564.109 m
The DSRequest from the log console
The DSResponse from the log console
The server side method invoked
Client side code
Data source xml file
Actual results Those with 14 or 15 decimal places are Strings when viewed on the client side. The rest are doubles.
Expected results All values should show up on the client side as doubles, not Strings.
NOTE I ran this in GWT development mode
Screen shot of actual results:
SmartClient Version: v10.1p_2016-01-14/Enterprise Deployment (built 2016-01-14)
Chrome browser, Version 48.0.2564.109 m
The DSRequest from the log console
Code:
{ dataSource:"example", operationType:"custom", operationId:"example", data:{ }, textMatchStyle:"exact", showPrompt:true, oldValues:{ }, requestId:"example_request1", fallbackToEval:false, lastClientEventThreadCode:"XRP4", bypassCache:true, dataProtocol:"getParams" }
Code:
{ affectedRows:0, data:[ { value08:127.1500000018, value07:127.15000000018, value09:127.150000018, value04:"127.15000000000018", value03:"127.15000000000002", value06:127.150000000018, value05:127.1500000000018, value10:127.15000018, value02:127.15, value01:127.15 } ], invalidateCache:false, isDSResponse:true, operationType:"custom", queueStatus:0, status:0 }
Code:
public DSResponse example(DSRequest dsRequest, HttpServletRequest request) { Map<String, Object> map = new HashMap<>(); map.put("value01", 127.15000000000000018); map.put("value02", 127.1500000000000018); map.put("value03", 127.150000000000018); map.put("value04", 127.15000000000018); map.put("value05", 127.1500000000018); map.put("value06", 127.150000000018); map.put("value07", 127.15000000018); map.put("value08", 127.1500000018); map.put("value09", 127.150000018); map.put("value10", 127.15000018); List<Map<String, Object>> data = new ArrayList<>(); data.add(map); return new DSResponse(data); }
Code:
package example.client.jsonstringnumber; import java.util.Arrays; import com.google.gwt.core.client.EntryPoint; import com.smartgwt.client.core.Function; import com.smartgwt.client.data.DSCallback; import com.smartgwt.client.data.DSRequest; import com.smartgwt.client.data.DSResponse; import com.smartgwt.client.data.DataSource; import com.smartgwt.client.data.Record; import com.smartgwt.client.widgets.HTMLFlow; public class JsonStringNumber implements EntryPoint { @Override public void onModuleLoad() { final String id = "example"; DataSource.load(id, new Function() { @Override public void execute() { runExampleWithDS(DataSource.get(id)); } }); } private void runExampleWithDS(DataSource ds) { String operationId = "example"; Record data = new Record(); ds.performCustomOperation(operationId, data, new DSCallback() { @Override public void execute(DSResponse dsResponse, Object data, DSRequest dsRequest) { Record record = dsResponse.getData()[0]; String msg = extractValuesFromRecordAsMessage(record); HTMLFlow htmlFlow = new HTMLFlow(); htmlFlow.setWidth(700); htmlFlow.setContents(msg); htmlFlow.draw(); } private String extractValuesFromRecordAsMessage(Record record) { String[] keys = record.getAttributes(); Arrays.sort(keys); String msg1 = ""; for (String key : keys) { Object value = record.getAttributeAsObject(key); msg1 += msgForKeyValuePair(key, value); } return msg1; } private String msgForKeyValuePair(String key, Object value) { String msg = "<br/><br/>map.get(" + key + ") is " + value; if (value != null) { msg += " and has type " + value.getClass(); } return msg; } }); } }
Code:
<DataSource ID="example"> <operationBindings> <binding operationType="custom" operationId="example" serverMethod="example"> <serverObject className="example.server.Example" lookStyle="new" /> </binding> </operationBindings> </DataSource>
Comment