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

Send JSON, receive stream? #125

Open
crazy4groovy opened this issue Aug 23, 2016 · 2 comments
Open

Send JSON, receive stream? #125

crazy4groovy opened this issue Aug 23, 2016 · 2 comments

Comments

@crazy4groovy
Copy link

Hi, like the client. Wondering if there is any way to send a JSON payload, and get back a application/octet-stream?

I'm getting a response parse error:
wslite.rest.RESTContentParseException: A JSONObject text must begin with '{' at 1 [character 2 line 1]

Or alternatively, is there a way to just disable auto JSON parsing? (Problem is, I must send a request that has content-type=application/json, but wslite seems to assume that that means JSON is always returned?)

@crazy4groovy
Copy link
Author

This "best-effort" hack seems to help patch it up a little bit:

ResponseBuilder.metaClass.parseJsonContent = { String content ->
        return content.trim().startsWith('[') ? new JSONArray(content) :
                        content.trim().startsWith('{') ? new JSONObject(content) :
                                        null
}

(Not saying this is the optimal solution.....)

@boekhold
Copy link

Looking at the code, it doesn't look like wslite assumes the return contentType is JSON. It takes the return contentType from HttpUrlConnection.getContentType(), which should be your application/octet-stream. And wslite doesn't try to parse the response as JSON unless it really recognizes it as something JSON encoded, eg contentType is one of the following: JSON(['application/json', 'application/hal+json', 'application/javascript', 'text/javascript', 'text/json']).

Are you sure your server responds with a Content-Type: application/octet-stream header?

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

No branches or pull requests

2 participants