Adarsh
Adarsh

Reputation: 217

Path Param giving null value when combined with POST method

I am trying to create a Restful Webservices for POST method.

I am trying to pass two variables as path params and get the JSON input from request body.

my code will look like below.


@POST

@Path("/{applicationNum}/{emailId}/example")

@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)

public ResponseVO testMethod(@PathParam("applicationNum") String applicationNum,@PathParam("emailID") String emailID,String jsonString);

The URL that i am using

/services/1111/[email protected]/example

where 1111 is the application number and [email protected] is the email id. I will get the value for jsonString from request body since this is a POST call.

On printing the output. I am able to get the application number but the email id is coming as null.

Please help me out to fix this problem.

Upvotes: 0

Views: 1442

Answers (2)

sitakant
sitakant

Reputation: 1878

As per your code:

@Path("/{applicationNum}/{emailId}/example")

@PathParam("emailID") String emailID

your path parameter name is emailId and you are accessing it using emailID (please spot the capitalization). So, you are getting null.

Solution
Either change your code to: @PathParam("emailId") String emailID,
or turn your path into: @Path("/{applicationNum}/{emailId}/example").

Both will work.

Upvotes: 1

Danny Daglas
Danny Daglas

Reputation: 1491

EmailID and EmailId is different (uppercase and lowercase D). Change one of them and this should fix it.

Upvotes: 2

Related Questions