「Java入門」ObjectMapper.writeValueAsString()のサンプル

2017年11月3日

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);
}

Java

Posted by arkgame