Can not deserialize instance of java.util.ArrayList out of VALUE_STRING Can not deserialize instance of java.util.ArrayList out of VALUE_STRING json json

Can not deserialize instance of java.util.ArrayList out of VALUE_STRING


This is the solution for my old question:

I implemented my own ContextResolver in order to enable the DeserializationConfig.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY feature.

package org.lig.hadas.services.mapper;import javax.ws.rs.Produces;import javax.ws.rs.core.MediaType;import javax.ws.rs.ext.ContextResolver;import javax.ws.rs.ext.Provider;import org.codehaus.jackson.map.DeserializationConfig;import org.codehaus.jackson.map.ObjectMapper;@Produces(MediaType.APPLICATION_JSON)@Providerpublic class ObjectMapperProvider implements ContextResolver<ObjectMapper>{   ObjectMapper mapper;   public ObjectMapperProvider(){       mapper = new ObjectMapper();       mapper.configure(DeserializationConfig.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);   }   @Override   public ObjectMapper getContext(Class<?> type) {       return mapper;   }}

And in the web.xml I registered my package into the servlet definition...

<servlet>    <servlet-name>...</servlet-name>    <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>    <init-param>        <param-name>com.sun.jersey.config.property.packages</param-name>        <param-value>...;org.lig.hadas.services.mapper</param-value>            </init-param>    ...</servlet>

... all the rest is transparently done by jersey/jackson.


Setting this attribute to ObjectMapper instance works,

objectMapper.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY);


do you try

[{"name":"myEnterprise", "departments":["HR"]}]

the square brace is the key point.