弹簧引导相同的API,但不同的返回类型的字节[]和JSON
如果请求Access Accept为type应用程序/JSON,我希望功能能够发送JSON列表,但如果请求标题为type Application/avro,则将其发送为字节数组(AVRO格式)。这应该适用于相同的休息端点,例如 /something /雇员。我可以使用相同的方法,但是不同的返回类型,Spring Boot会查看Accept标头并正确确定要调用哪种方法?
返回类型应该是什么?可以是没有任何类型的响应性吗?
I want the capability to send the JSON list like List if the request Accept Header is of type application/json, but send it in a byte array(avro format) if the request Header is of type application/avro. This should be for the same REST endpoint like /something/employee. Can I have the same method but different return types, will Spring Boot look at the accept header and correctly decide on which method to call?
What should be the return type? Can it be a ResponseEntity without any type?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以定义您的方法,以简单地返回naked
响应性
并检查Accept
标题的值以确定要返回的内容You can define your method to simply return a naked
ResponseEntity
and check the value of theAccept
header to determine what to return