@Serdeable
public record TagCriteriaRequest(List filters, Map sorts) {
}
Micronaut-Controller
@Controller("/tag")
@Version("1")
@Tag(name = "Tag")
public class TagController implements IHttpAction {
public TagController(IServiceAction iServiceAction) {
this.iServiceAction = iServiceAction;
}
@Override
public HttpResponse find(@QueryValue TagCriteriaRequest searchCriteria) {
var result = this.iServiceAction.find(searchCriteria);
return Result.match(()-> HttpResponse.ok(result.value), ()->HttpResponse.notFound(result.exception.getMessage()));
}
}
HTTP-Client
@Validated
@ExecuteOn(TaskExecutors.BLOCKING)
public interface IHttpAction {
@Get(value = "/{?searchCriteria*}")
HttpResponse find(C searchCriteria);
@Get(uri = "/{id}")
HttpResponse get(@PathVariable(name = "id") @Nonnull UUID id);
@Post
HttpResponse post(@Body T request);
@Put(uri = "/{id}")
HttpResponse put(@PathVariable(name = "id") @NotNull UUID id, @Body T request);
@Delete(uri = "/{id}")
HttpResponse delete(@PathVariable(name = "id") @NotNull UUID id);
}
Senden der Anfrage als
http://localhost:8080/tag?filters=[{"field":"string","operator":"EQUAL","values":{"additionalProp1":"string","additionalProp2":"string","additionalProp3":"string"}}]&sorts={"additionalProp1":"ASC","additionalProp2":"ASC","additionalProp3":"ASC"}
400 fehlerhafte Anfrage
{
"_links": {
"self": [
{
"href": "/tag?filters=%5B%7B%22field%22%3A%22string%22%2C%22operator%22%3A%22EQUAL%22%2C%22values%22%3A%7B%22additionalProp1%22%3A%22string%22%2C%22additionalProp2%22%3A%22string%22%2C%22additionalProp3%22%3A%22string%22%7D%7D%5D&sorts=%7B%22additionalProp1%22%3A%22ASC%22%2C%22additionalProp2%22%3A%22ASC%22%2C%22additionalProp3%22%3A%22ASC%22%7D",
"templated": false
}
]
},
"_embedded": {
"errors": [
{
"message": "Failed to convert argument [searchCriteria] for value [null] due to: Unexpected token VALUE_STRING, expected START_OBJECT \n at [Source: UNKNOWN; byte offset: #UNKNOWN]",
"path": "/searchCriteria"
}
]
},
"message": "Bad Request"
}
400 fehlerhafte Anfrage mit komplexem POJO-Objekt in der HTTP-Get-Methode von Micronaut ⇐ Java
-
- Similar Topics
- Replies
- Views
- Last post