Closed swicken-dotcms closed 1 year ago
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Second ticket reporting this: https://dotcms.zendesk.com/agent/tickets/112876
The conversion of the map of parameters to a json sent as payload in the post request should be tested with this overloaded method that was added to the json view tool:
post(final String url, final Map<String, String> headers,
final Map<String, Object> params, final boolean useParamsAsJsonPayload)
For example, this VTL code can be used:
$json.post("{{ENDPOINT}}", {
'Content-Type': 'application/json',
'Accept': 'application/json'
}, {
'testBoolean': true
}, true)
$json.post("https://postman-echo.com/post", {
'Content-Type': 'application/json',
'Accept': 'application/json'
}, {
'testBoolean': true
}, true)
The call above should return successfully:
{args={}, headers={x-forwarded-proto=https, x-forwarded-port=443, host=postman-echo.com, x-amzn-trace-id=Root=1-64ecdf43-72232b0c441bb701368e04a9, content-length=20, content-type=application/json, accept=application/json, user-agent=Apache-HttpClient/4.5.13 (Java/11.0.20), accept-encoding=gzip,deflate}, data={testBoolean=true}, form={}, files={}, json={testBoolean=true}, url=https://postman-echo.com/post}
Fixed, tested with he provided example and now it is working as expected
Tested on master // Docker // FF
Describe the bug The JSON viewtool does not support valid JSON types.
Valid JSON types are as follows: a string a number an object (JSON object) an array a boolean null
Currently, our implementation only accepts
Map<String, String>
meaning that the JSON tool will only accept string values. This causes issues if the receiver is expecting different types.https://github.com/dotCMS/core/blob/master/dotCMS/src/main/java/com/dotcms/rendering/velocity/viewtools/JSONTool.java#L195
Reproduced on: Latest, 5.3.8.X
To Reproduce Create a VTL with a call to an API that has non-string values, and attempt to fire it, for example
Expected behavior Our implementation should be able to handle any valid JSON types