「Java入門」ObjectMapper.writeValueAsString()のサンプル
Javaコード:
public static class Demo {
public List<String> strings = null;
public int number = 5;
}
public static void ignoreNullFieldByObjectMapper() throws JsonProcessingException {
ObjectMapper mapper = new ObjectMapper()
.setSerializationInclusion(JsonInclude.Include.NON_NULL);
String json = mapper.writeValueAsString(new Demo());
System.out.println(json);
}