Quarkus service passing parameter other than String type results in error

Viewed 230

I am developing an application using Vuejs which calls the Java service. This service is will take a parameter. If I pass the parameter as String then it would accept and continue with execution. However, this input corresponds to my Java Object Model type hence if I change the type to my Java Object type then I get the error:

Unable to obtain data, Error: Error: Request failed with status code 500

I would like to change the InputParameter type to my custom Java type can someone please tell me what I need to do for this?

Following is the working code with String type:

@POST
@Path("/generate")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@APIResponses(value = {
        @APIResponse(responseCode = "200", description = "returns list of JSON Objects"),
        @APIResponse(responseCode = "500", description = "An internal Server Error occurred")
})
public String generate(final String inputParameter){
    System.out.println(inputTemplate);
    return null;
}

The above code works fine and I am able to get the inputParameter printed, But I know that my inputParameter will always be my Custom java object type InputParameter so if I change the type then the execution won't detect the method and nothing is being printed and I get the error POST http://localhost:9001/generateTestData 500 (Internal Server Error):

@POST
@Path("/generate")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@APIResponses(value = {
        @APIResponse(responseCode = "200", description = "returns list of JSON Objects"),
        @APIResponse(responseCode = "500", description = "An internal Server Error occurred")
})
public String generate(final InputParameter inputParameter){
    System.out.println(inputTemplate.toString());
    return null;
}

Following is the call I am making in my vuejs application:

const headers = { 'Content-Type': 'application/json' }

this.$axios.post('/generate', { ...JSON.parse(inputParameter) }, { headers })
.then((response) => {
    console.log(JSON.stringify(response.data))
})
.catch((error) => {
    console.log(error)
})
0 Answers
Related