I want to have a generic bulk update call, where the client sends an array of objects for me to update. The body of the request would look like this:
Request Body
[
{
"id": 1,
"name": "noe",
"phone": "1234"
},
{
"id": 2,
"name": "noea",
"phone": "1235"
}
]
I've looked around and it seems like most marshalling providers can handle this in the body of the request. I've tried taking it a few different ways:
E[ ] or List< E > Parameters
How can I open what stream it's trying to read from? Am I missing some annotation or have the wrong @Consumes annotation? I did a little searching and I couldn't find anything that describes the problem I'm having.
@PUT
@Consumes( MediaType.APPLICATION_JSON )
@Produces( MediaType.APPLICATION_JSON )
@Path( "/multiedit" )
public Response edit( E[] objects ) {
}
Or
@PUT
@Consumes( MediaType.APPLICATION_JSON )
@Produces( MediaType.APPLICATION_JSON )
@Path( "/mutliedit" )
public Response edit( List<E> entities ) {
}
Produces
javax.json.JsonException: Unable to detect charset due to Stream closed
root cause: java.io.IOException: Stream closed
Wrapper class
After that I tried packing the array into a wrapper class.
public class EntityList<E> implements Serializable {
private List<E> entities;
}
@PUT
@Consumes( MediaType.APPLICATION_JSON )
@Produces( MediaType.APPLICATION_JSON )
@Path( "/multiedit" )
public Response edit( EntityList<E> entities )
{
}
This causes a mapping exception with my mapper api, Johnzon Mapper.
org.apache.johnzon.mapper.MapperException: Unsupported [<list of objects here>] com.my.project.EntityList<E>
I just want to accept an array of objects. I see it done in a bunch of different questions like here or here, but it doesn't work for me.
UPDATE: I can get the first two options working if I do a non-generic version of it. If I subclass a generic version of it and try to override it, it will still die with the same exceptions as stated.