Micronaut-core: Can a RequestBean access Body ?

Created on 27 Jun 2020  路  5Comments  路  Source: micronaut-projects/micronaut-core

Hello, congratulation for 2.0 release !

Expected Behaviour

RequestBean can access any information like @QueryValue
I'd like to access @Body

Actual Behaviour

@Body annotation can't be added to field

Thank you,
Robert

improvement

Most helpful comment

Would be nice to have this soon.

Our use case is that our app has two protocols/interfaces:

  • One of them is HTTP, which is handled by a controller.
  • The other one is via Kafka events, so we are receiving HTTP information in those events (like method, path, query parameters, headers, body, etc) and we convert it into the @RequestBean POJO to call the controller layer, as we don't want to duplicate the logic. Right now we have to map this Kafka event to two separate objects and then call the controller, but it can be simplified if @Body annotation is applicable to a request bean field.

All 5 comments

@Solido Please upload an example project with steps to reproduce the issue and details on what the error is or what behavior you are seeing

Hi !

I want to avoid having to use @RequestBean as one parameter and @Body as another
CompletableFuture bounds(@Valid @RequestBean Positionable render, @Body String body)

Currently @Body annotation is not supported as field marker so this code does not compile
`@Introspected
class Pt {

// THIS IS NOT WORKING
@Body String body

@NotNull
@PathVariable
String vid

@QueryValue
@NotNull
double dx

@QueryValue
@NotNull
double dy

}`

Thanks !

This is a little bit more complicated because other areas search for a body argument and make decisions about how it will be processed.

I know it's not trivial yet you see the problem having to search the request at two differents places.We'll refactor later if it land.

Thank you @jameskleeh !

Would be nice to have this soon.

Our use case is that our app has two protocols/interfaces:

  • One of them is HTTP, which is handled by a controller.
  • The other one is via Kafka events, so we are receiving HTTP information in those events (like method, path, query parameters, headers, body, etc) and we convert it into the @RequestBean POJO to call the controller layer, as we don't want to duplicate the logic. Right now we have to map this Kafka event to two separate objects and then call the controller, but it can be simplified if @Body annotation is applicable to a request bean field.
Was this page helpful?
0 / 5 - 0 ratings