Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Square's Retrofit response parsing logic: streaming?

Could you please explain Square's Retrofit response parsing logic. I'm interested in case when we should receive & parse a big json (>100Kb) - will Retrofit wait while all content will be received from server and only than parse it, or it will start to parse it immediately while getting stream data? My goal is to speedup response processing.

Are there any options about it available to configure?

like image 524
Sergii Avatar asked Feb 18 '15 09:02

Sergii


1 Answers

As soon as the HTTP client parses the headers, the InputStream will be handed back to Retrofit which will then hand it directly to the Converter. This means that as the underlying converter mechanism (say, Gson) is pulling bytes they are being read (and potentially blocking) directly from the network.

Note: this is only true if logging is off (as it should be in production / release builds). When logging is turned on beyond HEADERS level, the response body has to be read in its entirety into a byte[] in order to both log and hand the data to the converter.

like image 152
Jake Wharton Avatar answered Nov 14 '22 08:11

Jake Wharton