actions-on-google / actions-on-google-java

Java/Kotlin library for Actions on Google
Apache License 2.0
287 stars 39 forks source link

Allow deserializing a request and serializing a response using streams #39

Open ansman opened 4 years ago

ansman commented 4 years ago

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.

Fleker commented 4 years ago

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

ansman commented 4 years ago
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.

Fleker commented 4 years ago

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

ansman commented 4 years ago

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.

Fleker commented 4 years ago

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.