Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The JSON viewtool does not support valid JSON types, only strings #21529

Closed
swicken-dotcms opened this issue Jan 13, 2022 · 4 comments · Fixed by #25832
Closed

The JSON viewtool does not support valid JSON types, only strings #21529

swicken-dotcms opened this issue Jan 13, 2022 · 4 comments · Fixed by #25832
Assignees
Labels
OKR : Customer Success Owned by Arno OKR : Customer Support Owned by Scott Priority : 2 High QA : Approved Release : 22.03.12 Included in LTS patch release 22.03.12 Release : 23.01.9 Included in LTS patch release 23.01.9 Release : 23.09.6 Release Template Builder Team : Bug Fixers Type : Defect

Comments

@swicken-dotcms
Copy link
Contributor

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

 $json.post("{{ENDPOINT}}", {

      'Content-Type': 'application/json',

      'Accept': 'application/json'

    }, {
     'testBoolean': true
   
    })

Expected behavior
Our implementation should be able to handle any valid JSON types

@stale
Copy link

stale bot commented Dec 27, 2022

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.

@swicken-dotcms
Copy link
Contributor Author

Second ticket reporting this: https://dotcms.zendesk.com/agent/tickets/112876

@dsolistorres
Copy link
Contributor

dsolistorres commented Aug 23, 2023

Note for testing

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}

@bryanboza
Copy link
Member

Fixed, tested with he provided example and now it is working as expected

Image

Tested on master // Docker // FF

@erickgonzalez erickgonzalez added the LTS : Next Ticket that will be added to LTS label Aug 28, 2023
@erickgonzalez erickgonzalez added Next LTS Release and removed LTS : Next Ticket that will be added to LTS labels Nov 10, 2023
erickgonzalez added a commit that referenced this issue Nov 14, 2023
@erickgonzalez erickgonzalez added the Release : 23.01.9 Included in LTS patch release 23.01.9 label Nov 27, 2023
erickgonzalez added a commit that referenced this issue Nov 30, 2023
@erickgonzalez erickgonzalez added Release : 22.03.12 Included in LTS patch release 22.03.12 and removed Next LTS Release labels Nov 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OKR : Customer Success Owned by Arno OKR : Customer Support Owned by Scott Priority : 2 High QA : Approved Release : 22.03.12 Included in LTS patch release 22.03.12 Release : 23.01.9 Included in LTS patch release 23.01.9 Release : 23.09.6 Release Template Builder Team : Bug Fixers Type : Defect
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants