Configure Protobuf or ProtobufHttpMessageConverter to return null or empty fields

Viewed 157

Somewhat new to protobuf in the java ecosystem I am currently trying to configure an endpoint to return all fields, although currently, the endpoint only returns non-null, non-empty, non-zero fields.

Usually, I would do something like configure object mapper in application.yaml like so, and I am wondering if there is someway I can configure ProtobufHttpMessageConverter to yield me similar results

spring:
  jackson:
    default-property-inclusion: ALWAYS

for context, here's my ProtobufMessageConverterConfig

@Configuration
public class ProtobufMessageConverterConfig {

  @Bean
  public ProtobufHttpMessageConverter protobufHttpMessageConverter() {
    return new ProtobufHttpMessageConverter();
  }
}

and my Controller method that returns the model generated from my proto using the standard grpc-java plugin:

@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);
  }

SO, my question is:

  1. Can I configure ProtobufMessageConverterConfig to ensure all fields (including 0 or empty fields) get returned in my response or
  2. Can/should I add properties to my proto to ensure these fields get populated?

Thanks!

0 Answers
Related