I am new to JAVA Springboot and I have an error when trying to send a json by GET.
For the tests I use POSTMAN and this error sends me:
{
"status": "INTERNAL_SERVER_ERROR",
"message": "Required request parameter 'tags' for method parameter type List is not present"
}
json to prove:
"tags": [
"potable",
"contaminada",
"tratada"
]
The layers are quite simple:
Controller:
@GetMapping("/search")
public ResponseEntity<List<PropuestaEntity>> SearchTags(@RequestParam("tags") List<String> tag) {
List<PropuestaEntity> propuesta = propuestaServices.SearchTags(tag);
return ResponseEntity.ok(propuesta);
}
Services:
public List<PropuestaEntity> SearchTags(List<String> tag) {
return propuestaRepository.findByTags(tag);
}
Repository:
public interface PropuestaRepository extends MongoRepository<PropuestaEntity, Integer> {
List<PropuestaEntity> findByTags(List<String> tag);
}
Data in mongobd:
{
"titulo": "Análisis de la calidad del agua en el río X sdauiyuadiossd",
"tags": ["agua", "calidad", "contaminación", "metales pesados", "nutrientes"],
"estadoPropuesta":1
}
The main objective is to search for Proposals (English) by the tags that were previously assigned to them and list all the proposals containing those tags.
I don't really understand what you mean by "JSON to prove", but from the formatting it seems that you are presenting a request payload. In order to prove anything, you would need to show the whole request (including full request URL and payload).
If you send the
tagsvia request body, you need to change the annotation in your controller to look for thetagsin the request payload:In this case, your payload should look like this so it can be matched to the
Listtype in the controller method:If you really wanted to use the
@RequestParamannotation, you would have to include the tags as query params in the URL like this: