actions-on-google-java icon indicating copy to clipboard operation
actions-on-google-java copied to clipboard

Allow deserializing a request and serializing a response using streams

Open ansman opened this issue 6 years ago • 5 comments

To avoid having to first create an intermediary JSON string it would be great if an InputStream/OutputStream could be used to parse requests and serialize responses. Seeing as you are using gson already it would likely be a minor change.

I'd be happy to open a PR if this is something you feel worth implementing.

ansman avatar Dec 14 '19 16:12 ansman

I would be interested in seeing how this may be used.

Fleker avatar Dec 16 '19 15:12 Fleker

val request = inputStream.use { app.createRequest(it) }
val response = app.handleRequest(request, headers).get()
outputStream.use { response.writeTo(it) }

That would be the rough outline.

ansman avatar Dec 16 '19 15:12 ansman

Is there an advantage to doing this? I would like to see if there's a use case for it.

Fleker avatar Dec 16 '19 16:12 Fleker

The advantage is to not having to first convert the whole body into a string and then parsing it as JSON. It would save memory and time. This is not a big issue as the bodies are likely pretty small but since it's already supported by Gson is seems beneficial to just expose it.

ansman avatar Dec 16 '19 16:12 ansman

I guess if it's slightly more efficient that would be neat, as long as the API doesn't change and tests succeed a PR would be appreciated.

Fleker avatar Dec 16 '19 22:12 Fleker