Gregg
Gregg

Reputation: 35884

Micronaut Declarative Http Client Requires @Body or you get a key in the JSON request

I kind of wanted to get some verification before I send a PR in for the documentation. I have the following operations interface:

public interface StatusOperations {

    @Get
    HttpResponse<List<StatusResponse>> findAll();

    @Post
    Single<StatusResponse> save(StatusRequest statusRequest);
}

And then the declarative client interface:

@Client("/api/statuses")
public interface StatusClient extends StatusOperations {

    @Override
    @Get
    HttpResponse<List<StatusResponse>> findAll();

    @Override
    @Post
    Single<StatusResponse> save(StatusRequest statusRequest);
}

And here is StatusRequest:

@Introspected
public class StatusRequest {

    private UUID id;

    @NotNull
    private String message;

    // getter/setter stuff below
}

When I use the client to hit the API:

StatusResponse response = client.save(new StatusRequest("Hello")).blockingGet();

I am expecting this body to post:

{"message": "Hello"}

But what is actually posting is:

{"statusRequest": { "message": "Hello"}}

Which fails. However, if I modify the operations interface like so:

@Post
Single<StatusResponse> save(@Body StatusRequest statusRequest);

The post body is what I expect and everything work. The documentation doesn't talk about this at all so I don't know if it is just missing or if I've discovered a bug or what. Thanks for any feedback.

Upvotes: 1

Views: 2835

Answers (1)

saw303
saw303

Reputation: 9082

I ran into the same issue and I guess that the @Body is simply missing in the documentation. Would be great if you could raise a PR to clarify it.

Upvotes: 1

Related Questions