Reputation: 2044
I'm trying to PUT a JSON array to a JAX-RS service (using Jackson as JSON provider). The service is declared as follows:
@PUT
public Response setList(List<MyPojo> pojoList) {
...
}
When the method is called, the members of pojoList
are of type LinkedHashMap
instead of MyPojo
. So Jackson deserializes the list as a general "list of maps" instead of using the declared type.
I know that Jackson is able to deserialize typed lists when using its ObjectMapper
directly. But how can tell Jackson to do this when using it via JAX-RS? Is there a special @Json...
annotation for this that I'm missing?
Upvotes: 1
Views: 832
Reputation: 2044
I just discovered that this is a side effect of using CDI Interceptors (at least when using WELD as CDI provider). The proxy class used by the CDI interceptors destroys the Generics information of method parameters.
So the CDI proxy causes
public Response setList(List<MyPojo> pojoList) {
...
}
to appear as
public Response setList(List pojoList) {
...
}
to Resteasy (= our JAX-RS provider). Therefore it is deserialized as a "list of maps" by Jackson. Removing the Interceptor solves the issue, but unfortunately that's not a feasible option for us.
Upvotes: 1