1
votes

The rest API is failing with 400 Bad request with below response

javax.xml.bind.JAXBException - with linked exception: [org.codehaus.jettison.json.JSONException: A JSONObject text must begin with '{' at character 0 of ]

Below is my code,

API Resource

@GET
@Path("/getTeams")
@Produces(MediaType.APPLICATION_JSON)
public Response getTeamList(final TeamSearchRequest teamSearchRequest, @Context UriInfo uriInfo) {
      //Business
}

Request Class

@XmlRootElement(name = "teamSearchRequest")
public class TeamSearchRequest {
    private String searchText;
    private String searcherTeamId;
    public TeamSearchRequest(){}
//setters and getters
}

API URI - http://localhost:8080/letsplay/team/getTeams

API Request Body -

{
    "teamSearchRequest": {
        "searchText": "Mumbai",
        "searcherTeamId": "1"
    }
} 

Note - I have already checked all the similar questions in SO.

Any suggestions is most appreciated.

1
Do you have the media-moxy dependency set up for your project to enable JSON support? Assuming you are using Jersey..Prathap
@Prathap, I am using Spring Rest Integration and not Jersey, So media-moxy is not applicable.Srikanth A
Are you using JSONObject to map the request values? If so, you could have the JSONObject as the method argument instead of TeamSearchRequest and then do a jsonObject.getJSONObject("teamSearchRequest") to get the desired values.Prathap

1 Answers

0
votes

I think your JSON is wrong. It should look like this:

{

     "searchText": "Mumbai",
     "searcherTeamId": "1"

}