users@jersey.java.net

[Jersey] Trying to accept POST of array, getting "Consuming media type conflict"

From: Gary Moore <gary.moore_at_gmail.com>
Date: Mon, 2 May 2011 10:34:46 -0400

Hey guys,

I'm trying to allow clients to POST a single object for creation and
also POST an array of objects for bulk creation.  My method
definitions:

@Path("")
@Consumes({"application/json"})
@Produces({"application/json"})
public class RecordResource {


   @POST
   @Path("{type}/")
   public Object save(@PathParam("type") String type, Record record)
throws Exception { ... }


    @POST
    @Path("{type}/")
    public Object[] save(@PathParam("type") String type, Record[]
record) throws Exception {...}

}

The error when deploying is:

SEVERE: Consuming media type conflict. The resource methods public
java.lang.Object[] RecordResource.save(java.lang.String,Record[])
throws java.lang.Exception and public java.lang.Object
RecordResource.save(java.lang.String,Record) throws
java.lang.Exception can consume the same media type

I poked around and most of what I found on the list had to do with
inheritance conflicts. This class isn't extending any other class.

I've tried with Arrays and Lists, neither work. I also tried naming
the methods with different names.

Both methods should consume JSON.

Thanks,
Gary


--
Gary Moore
http://www.gmoore.net