users@jersey.java.net

[Jersey] (De)Serializing Custom MIME types

From: Eric Stein <steine_at_locustec.com>
Date: Fri, 27 Jun 2014 19:24:11 +0000

I read in an old thread that support for custom MIME types should work out of the box:



    Anything "+json" should work out of the box

                - Martin Maula-3

                http://jersey.576304.n2.nabble.com/Application-Specific-content-types-and-JAXB-annotations-td6380235.html



but that hasn't been my experience. I have a resource


    @POST
    @Consumes("application/vnd.locustec.eim.initial.query.v1+json")
    @Produces("application/vnd.locustec.eim.secured.query.v1+json")
    public Response createSecuredQuery(

            @ApiParam(required = true) final InitialQueryBean initialQuery) {



I have a simple bean:

@XmlRootElement(name = "InitialQuery")
public final class InitialQueryBean {

    @JsonProperty("initialQuery")
    public String getInitialQuery() { ...
    public void setInitialQuery(final String initialQuery) { ...

    @JsonProperty("restrictQueryToSites")
    public Set<String> getRestrictQueryToSites() {...
    public void setRestrictQueryToSites(final Set<String> restrictQueryToSites) { ...

}



and a simple test case:
    @Test
    public void testCreateSecuredQuery() {

        final Response response =
                this.target("/secured-queries")
                .request("application/vnd.locustec.eim.secured.query.v1+json")
                .post(Entity.entity(this.initialQueryBean, "application/vnd.locustec.eim.initial.query.v1+json"));



but I'm seeing

org.glassfish.jersey.message.internal.MessageBodyProviderNotFoundException:

MessageBodyWriter not found for

media type=application/vnd.locustec.eim.initial.query.v1+json,

type=class com.locustec.eim.query.rest.InitialQueryBean,

genericType=class com.locustec.eim.query.rest.InitialQueryBean.



If I change everything to MediaType.APPLICATION_JSON, it my test runs just fine. So what am I doing wrong here? I'm running Jersey 2.4.