Exclude null objects from JSON array with Gson
问题 I'm using Gson to parse my REST API calls to Java objects. I want to filter out null objects in an array, e.g. { list: [ {"key":"value1"}, null, {"key":"value2"} ] } should result in a List<SomeObject> with 2 items. How can you do this with Gson? 回答1: Answer: The Custom Serializer You can add a custom serializer for List.class which would look like: package com.dominikangerer.q27637811; import java.lang.reflect.Type; import java.util.Collections; import java.util.List; import com.google.gson