JAX-RS 2.1 parameter type Object.class

by flavio.donze   Last Updated July 12, 2019 14:26 PM - source

Having this example JAX-RS web-service, the second parameter of the getByAttribute is of the type Object.class.

@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@Path("/POJOService")
public interface POJOService extends BasicService {

    @GET
    @Path("/getByAttribute")
    SampleObject getByAttribute(@QueryParam("attribute") String attribute, @QueryParam("value") Object value);

}

This will result in an error:

Payload: Parameter Class java.lang.Object has no constructor with single String parameter, static valueOf(String) or fromString(String) methods

I was thinking of adding a provider of javax.ws.rs.ext.ParamConverterProvider which will pass the type in the JSON string. But maybe there is a best practice solutions for this problem?

Migrating the communication layer of an existing enterprise server/client application to JAX-RS 2.1.
Using Apache CXF and Eclipse Rest Client for MicroProfile.

EDIT: The client will call the service with different types:

service.getByAttribute("name", "example"); // string, used for this test which throws the exception
service.getByAttribute("id", 99); // integer
service.getByAttribute("author", user); // object instace of User.class


Related Questions


The host for cxf wadl file is picking up incorrect

Updated January 29, 2018 05:26 AM