简体   繁体   English

Spring rest 调用 JSON 来自 Z0ECD11C1D7A287401D148A23BBDZ2F 发生器的响应大小

[英]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:我使用调试模式来找出流程:

  1. After hitting the URL in postman, backend rest controller gets triggered.在 postman 中击中 URL 后,后端 rest Z594C103F2C6E010C3D8AB059 被触发。
  2. Outputstream object from response object (as http request & response both captured by rest controller).来自响应 object 的输出流 object(如 http 请求和响应均由 Z65E8800B5C6800AAD896F888B 控制器捕获)。
  3. Create a output adapter from that response object with help of JSON generator.在 JSON 生成器的帮助下,从该响应 object 创建一个 output 适配器。
  4. With adapter, callable statement is created ( JDBC is being used with stored procedure to fetch data from oracle DB.)使用适配器,创建可调用语句( JDBC 与存储过程一起用于从 oracle DB 获取数据。)
  5. JSON generator object methods invoked to write as JSON response.调用 JSON 生成器 object 方法以写入 JSON 响应。

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.

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