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

Add convenience methods to controller specs to work with JSON #1258

Closed
ipolevoy opened this issue Dec 13, 2022 · 1 comment
Closed

Add convenience methods to controller specs to work with JSON #1258

ipolevoy opened this issue Dec 13, 2022 · 1 comment

Comments

@ipolevoy
Copy link
Member

Example posting JSON as an object:

Map requestDoc = ...
request().json(requestDoc).post("create"); 

JSONMap response = responseContentMap();

...
JSONList response = responseContentList();

@ipolevoy
Copy link
Member Author

ipolevoy commented Dec 14, 2022

Added in controllers:

@POST
    public void index1(){
        JSONMap request = .....
        respondJSON(request);
    }

The method respondJSON() also sets the Content-Type=application/json


Controller Specs:

Sending requests:

request().json(obj).post("index1"); 

will convert the obj to a JSON format (String, Map, List, Object). Will also set Content-Type=application/json automatically

Parsing controller output:

JSONList responseList = responseJSONList();
JSONMap responseMap = responseJSONMap();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant