Ember JsonApi with Jax-Rs content type on Posts

128 views Asked by At

I am using Ember-Data clientside and Tomee7 with Jax-RS on the Server.

I would very much like use the Ember-Data's JsonAPIAdapter and adhere to the jsonAPI specifications

If I understand correctly, all HTTP communications must have the Content-Type header set to application/vnd.api+json

The Problem when I try to POST something to the Server I get a 415 Unsupported Media error

I've decorated my services like this:

@POST
@Consumes("application/vnd.api+json")
@Path("somePostEndPoint")
public Response postService (@FormParam "someData" String someData) {
        //....
}

but I am returned:

An application/x-www-form-urlencoded form request is expected but the request media type is application/vnd.api+json. Consider removing @FormParam annotations

When I make the Request outside of EmberData (with Postman) Everything works fine.

I understand the @FormParam requires Content-Type: application/x-www-form-urlencoded. Could I use something else?

It would be a shame to not get to use the JsonApiAdapter. :(

does anyone have any Ideas what I could try?

Thanks!

1

There are 1 answers

0
localyost On BEST ANSWER

Ok a colleague of mine figured it out:

@Path("somePostEndPoint")
    @POST
    @Produces(value={"application/vnd.api+json",MediaType.APPLICATION_JSON})
    @Consumes(value={"application/vnd.api+json",MediaType.APPLICATION_JSON})

    public Response postService (String someData) {
      //...
    }
  • Do not use @FormParam, just set a String. @FormParam requires the Content-Type: application/x-www-form-urlencoded

  • use @Consumes(value={"application/vnd.api+json",MediaType.APPLICATION_JSON})

this worked for us.