简体   繁体   中英

Spring rest call JSON response size from JSON generator

In my project I can't get a direct return statement.

Via JSON generator I can see some methods that set output to JSON string.

I used debug mode to find out the flow:

  1. After hitting the URL in postman, backend rest controller gets triggered.
  2. Outputstream object from response object (as http request & response both captured by rest controller).
  3. Create a output adapter from that response object with help of JSON generator.
  4. With adapter, callable statement is created ( JDBC is being used with stored procedure to fetch data from oracle DB.)
  5. JSON generator object methods invoked to write as JSON response.

Methods are

writeOutputParameterStart(stored proc. Result)

writeOutputParameterEnds(stored proc. Result)

I need to find the JSON string.

Is the JSON string created internally by Jackson library? Is there any means I can get the size of that response in JSON?

So basically every jsonGenerator object has underlying output stream or writer. So we can invoke getOutputBuffered() method on jsonGenerator object which will return the size of buffered response in int.

So my response size here is 1900 bytes (1.9KB ) which I can directly see in postman page & now I can also print this on log so that a tool SPLUNK can retrieve from server log of my application

NOTE- we should call this method before jsonGenerator is flushed. So once any stream is flushed we can't get buffered data size.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM