jobe
jobe

Reputation: 325

JSON to POJO conversion error in Rest webservice

I'm using wildfly 10 and REST and have the following error:

08:15:19,827 ERROR [org.jboss.resteasy.resteasy_jaxrs.i18n] (default task-22) RESTEASY002010: Failed to execute: javax.ws.rs.NotSupportedException: RESTEASY003065: Cannot consume content type

I have the following request:

http://localhost:8080/MyApp/rest/myService/test?data=%7B%22MyData%22:%7B%22id%22:%223d87e735-4f88-49bd-929b-5f2b646e853e%22,%22name%22:%22myname%22%7D%7D

--> parameter is:

data:{"MyData":{"id":"3d87e735-4f88-49bd-929b-5f2b646e853e","name":"myname"}}

My service:

@Path("/myService")
@Produces(MediaType.APPLICATION_JSON)
@Stateless
public class StammdatenRestRessource {

  @POST
  @Path("/test")
  @Consumes(MediaType.APPLICATION_JSON)
  public Response test(final MyData data) {
      System.out.println(data);
      return Response.ok().build();
  }
}

and my POJO:

@XmlRootElement
@Entity
public class MyData{

@Id
@Column(name = "ID")
private String id;

private String name;

public MyData() {
    id = UUID.randomUUID().toString();
}

// getters & setters
}

Any idea?

Upvotes: 2

Views: 8484

Answers (3)

jobe
jobe

Reputation: 325

Ok i found a solution. I have to put my json object in the request body and not the address.

Upvotes: 0

jpkroehling
jpkroehling

Reputation: 14061

Make sure that you are sending a "Content-type" header with a value of "application/json":

curl -H 'Content-type: application/json' http://localhost:8080/MyApp/rest/myService/test?data=%7B%22MyData%22:%7B%22id%22:%223d87e735-4f88-49bd-929b-5f2b646e853e%22,%22name%22:%22myname%22%7D%7D

Upvotes: 1

Sharon Ben Asher
Sharon Ben Asher

Reputation: 14328

The glaring point to me is the id field. the value "id" will not parse into a UUID object (you can try to call UUID.fromString() and see for yourself). take a "real" UUID value and see if this is the problem

here's one for ya "3d87e735-4f88-49bd-929b-5f2b646e853e"

Upvotes: 0

Related Questions