Comments (4)
This is a good question and for large JSON structures a good decision not to serialize in memory.
But unfortunately I'm not yet familiar with Gson. The only example I can give you is from the test cases. I'd highly apreciate if you find a solution for Gson and tell us how it works.
As I don't want to add heavy dependencies to DavidWebb, there could be a way to extend it more or less like this (pseudo-code):
interface StreamRunnable {
void doTheStreaming(OutputStream outputStream);
}
Then one could give an object implementing this interface as the body to DavidWebb and it calls the streaming method at the time it processes the body.
from davidwebb.
Thank you for your reply hgoebl. The test case is very helpful.
I'm new to GSON as well but it basically allows easily serializing an object into JSON as a stream, which allows the HttpURLConnection to start sending chunks of data as chunked Transfer Encode (without knowing the content length) as soon as each serialized token is available and take advantage of low memory-usage in the client. At least that's what I understood, so it would be great to have DavidWebb wrapper being able to send requests with chunked transfer encoding mechanism.
I think that way of extending it would be very good, but somehow DavidWebb would have to add the Transfer Encoding Http header instead the Content-Length if I'm not mistaken (apart from the Content-Encoding to optimize even more the chunks transfer).
from davidwebb.
DavidWebb should already set the header apropriately (when it's not able to find out the content length in advance), have a look at this.
If you find a way to tweak Gson so it's possible to use it without a change of DavidWebb, I'd be glad.
If not, I'll try to find a workaround like mentioned above. Should not be too hard, but currently I'm very busy, so it could take some time.
from davidwebb.
Thanks again. It's great that it already deals with the headers from its content length. I'll play around with it and see if I can find a way. I'd let you know if I'm successfull.
from davidwebb.
Related Issues (20)
- Send a file on request HOT 5
- How can we get the progress of the request? HOT 3
- Add a complete set of params to request: `params(Map<String, Object>)`
- handling multiple values with identical parameter name HOT 7
- Getting NetworkOnMainThreadException HOT 1
- Canceling a request HOT 1
- Allow to get the result as InputStream HOT 6
- PATCH requests? HOT 2
- Crashes after update UI HOT 3
- it not support proxy? HOT 2
- Setting multiple headers HOT 2
- Dependency on org.json HOT 7
- Server response code 204 HOT 2
- How to handle error if there is no internet connection HOT 1
- SSL error HOT 10
- Middleware (hooks) HOT 2
- cannot add query parameters to put request HOT 5
- An exception occurred when response content-encoding is UTF-8 HOT 1
- No support for PATCH verb HOT 3
- Oauth2 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from davidwebb.