[英]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.通过 JSON 生成器,我可以看到一些将 output 设置为 JSON 字符串的方法。
I used debug mode to find out the flow:我使用调试模式来找出流程:
Methods are方法是
writeOutputParameterStart(stored proc. Result)
writeOutputParameterEnds(stored proc. Result)
I need to find the JSON string.我需要找到 JSON 字符串。
Is the JSON string created internally by Jackson library? JSON 字符串是由 Jackson 库在内部创建的吗? Is there any means I can get the size of that response in JSON?
有什么方法可以在 JSON 中获得该响应的大小?
So basically every jsonGenerator object has underlying output stream or writer.所以基本上每个 jsonGenerator object 都有底层 output stream 或 writer。 So we can invoke getOutputBuffered() method on jsonGenerator object which will return the size of buffered response in int.
因此我们可以在 jsonGenerator object 上调用 getOutputBuffered() 方法,该方法将以 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所以我的响应大小是 1900 字节(1.9KB),我可以在 postman 页面中直接看到它,现在我也可以在日志上打印它,以便工具 SPLUNK 可以从我的应用程序的服务器日志中检索
NOTE- we should call this method before jsonGenerator is flushed.注意——我们应该在 jsonGenerator 被刷新之前调用这个方法。 So once any stream is flushed we can't get buffered data size.
因此,一旦任何 stream 被刷新,我们就无法获得缓冲数据大小。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.