0
I’m doing a simple user registration with Java and Angularjs.
My javascript request looks like this:
$http({
url: "rest/user/register",
method: "POST",
data: $scope.newUser
});
In java, I have a method that receives the data in a POJO.
@Produces(MediaType.APPLICATION_JSON + ";charset=utf-8")
@Consumes(MediaType.APPLICATION_JSON + ";charset=utf-8")
@POST
@Path("/register")
public String register(UserPojo userPojo){
return "teste";
}
The problem I’m facing is that in my statement UserPojo
, I’m being forced to put the note @XmlRootElement
so that it works normally.
If I take the note, the following errors occur:
GRAVE: A message body reader for Java class br.com.taskmanagement.pojo.UserPojo,
and Java type class br.com.taskmanagement.pojo.UserPojo,
and MIME media type application/json; charset=UTF-8 was not found.
The registered message body readers compatible with the MIME media type are:
application/json; charset=UTF-8 ->
I’d like to know how to do without @XmlRootElement
, because I’m not sending anything with XML.
Using some lib from Json? Ex:
jersey-media-json-jackson
– DiegoAugusto
@I’m wearing jersey-json.jar
– Guilherme Nass
Try using this to test for the error some: https://mvnrepository.com/artifact/org.glassfish.jersey.media/jersey-media-json-jackson/2.25
– DiegoAugusto
I’m not familiar with jersey-json, but you may need to use the @Xmlrootelement annotation with it.
– DiegoAugusto
@Diegoaugusto I tried with the lib you commented, but it didn’t work either :(
– Guilherme Nass
Do you use Maven? If yes you can add its dependencies?
– DiegoAugusto
@Diegoaugusto I’m not using Maven, all in hand.
– Guilherme Nass
Get it, get it. http://stackoverflow.com/questions/12179737/jersey-json-media-type-application-json-was-not-found
– DiegoAugusto