Skip to content

Fix Reactive JsonView + HttpEntity handling [SPR-16098] #20647

@spring-projects-issues

Description

@spring-projects-issues

Daniel Jones opened SPR-16098 and commented

@JsonView annotations aren't being honoured when the return type is a >= 2 nested generic type. i.e. Mono<ResponseEntity<UserAccount>>. For example (in Kotlin, but the same occurs with Java):

@RestController
@RequestMapping("/users")
class UserController(
        val userAccountRepository: UserAccountRepository,
        val passwordEncoder: BCryptPasswordEncoder
) {

    @JsonView(UserView.PublicView::class)
    @PostMapping
    fun create(@RequestBody userAccount: UserAccount, uriBuilder: UriComponentsBuilder): Mono<ResponseEntity<UserAccount>> {
        return userAccountRepository
                .save(UserAccount(null,
                        userAccount.username,
                        passwordEncoder.encode(userAccount.password))).map {
            ResponseEntity.created(uriBuilder.path("/users/${it.id}").build().toUri())
                    .body(it)
        }
    }
}

This is because in AbstractMessageWriterResultHandler.writeBody(...) where bodyType is resolved, ResolvableType.forMethodParameter(...) strips the typeProvider when extracting the nested generics in ResolvableType#getNested()

There was some discussion around this in #19257 which has now been closed, hence I've created a new issue.


Affects: 5.0 GA

Issue Links:

Referenced from: commits c530745

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions