0

With micronaut.io, how do I setup POJO validation of reactive HTTP body content? It works for the syncronous case, ie:

@Post("/sync/{id}")
HttpResponse createSync(String id, @Body @Valid SomePojo pojo) {
    ...
}

but it doesn't work in the async case:

@Post("/async/{id}")
Single<HttpResponse> createAsync(String id, @Body @Valid Single<SomePojo> pojoProducer) {
    ...
}

Thanks

4

1 回答 1

0

我发现的解决方法是在控制器中声明一个触发验证的方法并以这种方式使用它:

    pojoProducer
        .map(pojo -> validate(pojo))
        ...

public <T> T validate(@Valid T t) {
    return t;
}

但如果框架可以为我做这将是很好的..

于 2018-10-23T14:31:02.170 回答