I am trying to auto serialize the below class as a parameter object via GSON, but my vocabularyCategoryMap always gets set to null
import lombok.Data;
import java.util.List;
import java.util.Map;
@Data
public class SearchRequestParameters {
private int queryOffset;
private String query;
private Map<String, List<String>> vocabularyCategoryMap;
private boolean sortByDate;
}
Here is the read from method from my GSON provider for JAX-RS
@Override
public Object readFrom(final Class<Object> type, final Type genericType, final Annotation[] annotations, final MediaType mediaType,
final MultivaluedMap<String, String> httpHeaders, final InputStream entityStream) throws IOException, WebApplicationException {
try (InputStreamReader streamReader = new InputStreamReader(entityStream, UTF_8)) {
return getGson().fromJson(streamReader, type);
}
}
This read from method has worked fine for me across a multitude of request parameter objects so far, but none of them have had a collection nested within a map. All of the examples for dealing with the situation (from googling) have suggested using specific type tokens, but that would break the generic nature of the existing gson provider. What is the best practices way for serializing nested json objects with GSON when using JAX-RS so that multiple GSON providers are not required?