配置Protobuf或Protobufhttpmessageconverter返回null或空字段
protobuf
在Java生态系统中有所了解,我当前正在尝试配置端点以返回 all fields,尽管当前,端点仅返回 nonnon-null , non-empty , non-Zero 字段。
通常,我会做类似的事情,例如在 application.yaml
之类的类似中,我想知道是否有某种方法可以配置Protobufhttpmessageconverter,以给我带来类似的结果
spring:
jackson:
default-property-inclusion: ALWAYS
,这是我的 proteg> protabobufmessageConverterConferterConfig
@Configuration
public class ProtobufMessageConverterConfig {
@Bean
public ProtobufHttpMessageConverter protobufHttpMessageConverter() {
return new ProtobufHttpMessageConverter();
}
}
和我的控制器
方法,该方法使用标准 grpc-java
插件返回我的原型生成的模型:
@GetMapping(value = "/assets", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<GetAssetsResponse> getAssets() {
// do something to populate GetAssetsResponse
final var reply = GetAssetsResponse.newBuilder().build();
return new ResponseEntity<>(reply, HttpStatus.OK);
}
所以,我的问题是:
- 我可以配置ProtoBufMessageConverterConfig以确保所有字段(包括0或空字段)都会在我的响应中返回,或者
- 可以/应该/应该在原触发中添加属性以确保这些字段被填充吗?
谢谢!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论