I don't know what to do to fix it. When accessing localhost:8080/pets/findByStatusLocal
is returning the following error.
Error
Error id 9175b683-f00f-4a8d-9246-a30eb0f8865f-5, javax.ws.rs.ProcessingException: RESTEASY003145: Unable to find a MessageBodyReader of content-type application/json and type interface java.util.List
Pet.java
package org.test;
public class Pet {
private Long id;
private String name;
public Pet() {
this(null, null);
}
public Pet(Long id, String name) {
this.id = id;
this.name = name;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
application.properties
org.test.PetService/mp-rest/url=https://petstore.swagger.io/v2/
org.test.PetService/mp-rest/scope=javax.inject.Singleton
PetService.java
package org.test;
import java.util.List;
import java.util.concurrent.CompletionStage;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;
@Path("/pet")
@RegisterRestClient
public interface PetService {
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("findByStatus")
public List<Pet> findByStatus(@QueryParam("status") String status);
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("findByStatus")
public CompletionStage<List<Pet>> findByStatusAsync(@QueryParam("status") String status);
}
PetResource.java
package org.test;
import java.util.List;
import java.util.concurrent.CompletionStage;
import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import org.eclipse.microprofile.rest.client.inject.RestClient;
@Path("/pets")
public class PetResource {
@Inject
@RestClient
PetService petService;
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("findByStatusLocal")
public List<Pet> methodname(@QueryParam("status") String status) {
return petService.findByStatus(status);
}
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("findByStatusLocalAsync")
public CompletionStage<List<Pet>> async(@QueryParam("status") String status) {
return petService.findByStatusAsync(status);
}
}
Is it an error in the source code or could it be in the project configuration? Thank you very much
*** I made the correction - pom.xml:
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-jackson</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-rest-client-jackson</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-rest-client</artifactId>
</dependency>
You need the quarkus-resteasy-reactive-jackson
to write (and read) JSON object. Alternatively, you can also use the -jsonb
extension. However, I highly recommend Jackson in this case as it offers many more features.
So, in your pom.xml
file, add:
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-reactive-jackson</artifactId>
</dependency>