0

My REST API must work with gRPC objects as input parameters.

The most simple example is:

GET http://localhost:8083/api/books?page.number=1&page.size=30

where the proto definition is:

message PagedMessage {
    Page page = 1;
}

message Page {
    int32 number = 1;
    int32 size = 2;
}

The controller is:

@RequestMapping(value = "/api/books")
public class ObjectOps {

   @Autowired
   private BooksService booksService;

   @GetMapping(value = "/")
   @ResponseBody
   BooksList listBooks(@RequestParam PagedMessage request) {
      return booksService.getBooks(request);
   }
}

And in the application I have this bean:

@Bean
ProtobufJsonFormatHttpMessageConverter protobufJsonFormatHttpMessageConverter() {
      return new ProtobufJsonFormatHttpMessageConverter();
}

The only way it worked for me is to pass the paging information as GET body:

{ 
   "page" : {
      "number": 1,
      "size": 30
   }
}

but it will be great to have the list books method object be populated from the request path parameters.

ILAPE
  • 47
  • 1
  • 5

1 Answers1

0

I think you can just remove the @RequestParam annotation and Spring will populate the object. Referenced by this answer: https://stackoverflow.com/a/16942352/8075423

Radoslav Hubenov
  • 195
  • 1
  • 1
  • 10
  • Unfortunately, this does not work for gRPC data objects (messages), but for plain POJOs. – ILAPE Feb 09 '19 at 07:04