Can a RequestBean access Body ?
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
@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
@RequestBeanPOJO 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@Bodyannotation is applicable to a request bean field.
Hi all,
What about this?
As workaround if you place the @Body annotation before @RequestBean it works. I think its a question of order.
Update on this: 2024
If the @Body annotation is placed before the @RequestBean annotation, it takes precedence, which means any fields annotated with @field (such as @field:PathVariable or @field:Query) will not be considered.
@Serdeable(naming = SnakeCaseStrategy::class)
data class Demo {
@field:PathVariable("mark_id")
val markId: String?,
val operation: String?,
val timeToLive: Int?
}
In the example above, all fields except mark_id will be populated.
Conversely, if you place @RequestBean before @Body, the annotations will work correctly, but you must write the request body field names in snake case. Attempts to use @JsonProperty or @field:JsonProperty to modify this behavior are ineffective.
@Serdeable(naming = SnakeCaseStrategy::class)
data class Demo {
@field:PathVariable("mark_id")
val markId: String?,
val operation: String?,
val time_to_live: Int?
}