英文:
Retrieve streaming response body with additional data
问题
我有一个API,它会做出响应:
@PostMapping
public StreamingResponseBody export(<variables>) {
return outputStream -> method(variables);
}
包含此API的导出服务并未连接任何数据源 - 它只是一个简单的微服务。 变量主要是:带有附加标志的非常大的JSON文件。
问题是,导出中的方法还会提取额外的数据 List<Object> data
,这些数据在进一步处理时是必需的。
如何将 StreamingResponseBody
与 data
一起传递?
任何其他现成的解决方案也都可以。
英文:
I have an API which responds with:
@PostMapping
public StreamingResponseBody export(<variables>) {
return outputStream -> method(variables);
}
Export service (which contains this API), does not have any data source attached - it is a simple microservice.
Variables mostly are: really big JSON file with additional flags.
Problem is, that the method at the export also extracts additional data List<Object> data
, required for further processing.
How to pass StreamingResponseBody
together with data
?
Any other out of the box solution would be great too.
答案1
得分: 0
我已经选择了一个ObjectOutputStream的实现。我已经创建了:
public class Response implements Serializable {
private byte[] document;
private List<Object> data;
}
并且方法如下:
public void method(OutputStream os) throws Exception {
try (ObjectOutputStream oos = new ObjectOutputStream(os)) {
oos.writeObject(buildObj());
}
}
英文:
I have went with an ObjectOutputStream implementation. I have created:
public class Response implements Serializable {
private byte[] document;
private List<Object> data;
}
and method just:
public void method(OutputStream os) throws Exception {
try (ObjectOutputStream oos = new ObjectOutputStream(os)) {
oos.writeObject(buildObj());
}
}
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论