2

I have the following application details, where I am adding protobuf to an existing spring boot application.

pom.xml dependencies

<dependency>
            <groupId>com.google.protobuf</groupId>
            <artifactId>protobuf-java</artifactId>
            <version>3.21.1</version>
        </dependency>
        <dependency>
            <groupId>com.googlecode.protobuf-java-format</groupId>
            <artifactId>protobuf-java-format</artifactId>
            <version>1.4</version>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>4.5.2</version>
        </dependency>

Application.java I have added the formatter as given below in Application.java

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

Spring boot version used: 2.6.9

The below is the API controller

 @PostMapping(value = "/reports/process", consumes = "application/x-protobuf")
    public ResponseEntity<Boolean> processReports(
            @Parameter(description = "Process report data", required = true)
            @RequestBody ReportCollection executionReports) {

I have written and generated the .proto file for Java (above application) The same .proto file is used in python and python generated the data and posted to the above API using application/x-protobuf in both the Accept and Content-Type headers.

However the Spring boot API that received the payload throws the below exception

Could not resolve parameter [0] in public org.springframework.http.ResponseEntity<java.lang.Boolean> com.*.ReportsApiController.processReports(com.*.ReportCollection): Content type 'application/x-protobuf;charset=UTF-8' not supported

I have been googling for solution and not able to get this fixed, can you please help me

Saran
  • 99
  • 2
  • 14
  • Does this answer your question? [How to consume protobuf parameters using Spring REST?](https://stackoverflow.com/questions/40023714/how-to-consume-protobuf-parameters-using-spring-rest) – Martin Zeitler Jul 19 '22 at 08:07
  • I tried this solution, it works fine, but it is returning status code `406` now. Also, it looks like this is applicable for MVC, is it ok to use this for rest API only. – Saran Jul 19 '22 at 08:17

0 Answers0