Many of theSmartSDK WebAPI endpoints accept JSON encoded entities for payload when starting jobs. These JSON values are the only way to set configuration for that job type, and are documented in the WebAPI Specifications for the appropriate endpoint.
For example, in order to enable scan previews when scanning via the /rws/service/scanner/jobs
endpoint, you construct a jobSettings
JSON blob with the "originalPreview
" key set to a JSON Boolean.
However, the JSON parser on some devices may not be very strict. On G2 and G2.5 devices it is possible to pass in this key-value pair encoded as a JSON String. Even though an internal ClassCastException might be thrown, the value was still coerced to a Boolean and processing would continue without affecting the results of the request.
For example, the JSON payload might be presented as the following for input to the start Scan endpoint, and the preview would still come up on G2 and G2.5 devices after scanning was complete (assuming no other conflicts):
{
"jobSetting": {
"originalPreview": "true",
"originalOrientation": "unreadable",
"originalSide": "one_sided",
"scanResolution": "300",
"pdfSetting": {
"pdfA": true
},
"scanColor": "color_text_photo",
"originalSize": "na_letter_landscape"
}
}
G3 devices are stricter with respect to these JSON value types, and in the case of an expected Boolean being presented as a String value, you might see a NoSuchMethodException
associated with the JSON key class that is responsible for the JSON parsing. This is not an internal Exception, though, and is seen as a parse failure. This results in the key being set to the default value. In the case of orignalPreview
, it would be set to False.
Our recommendation is to not rely on loose JSON parsing and to construct your JSON HTTP entities using the JSON types documented in the WebAPI Specification for the endpoint. This means your application should work the same across all devices, including current and future devices.
Thus, we'd want to correct the JSON above so that Boolean keys values were presented as JSON Booleans. e.g.:
{
"jobSetting": {
"originalPreview": true,
"originalOrientation": "unreadable",
"originalSide": "one_sided",
"scanResolution": "300",
"pdfSetting": {
"pdfA": true
},
"scanColor": "color_text_photo",
"originalSize": "na_letter_landscape"
}
}