我有以下JSON:
{
"terms": ["Hello", "", "World"]
}
和这个POJO:
@JsonInclude(NON_EMPTY)
public class Query {
public List<String> terms = new ArrayList<>();
}
我想在反序列化时忽略空字符串。 (仅加载"Hello" and "World"
)
public class EmptyStringValueInList {
public static void main(String[] args) throws IOException {
ObjectMapper mapper = Jackson.newObjectMapper();
Query query = mapper.readValue("{\"terms\": [\"Hello\", \"\", \"World\"]}", Query.class);
System.out.println(query.terms.size()); // print 3, I expect 2
}
}
我尝试了几种配置,但没有效果。