import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.MapperFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
ObjectMapper mapper = new ObjectMapper();
mapper.disable(SerializationFeature.WRITE_NULL_MAP_VALUES);
mapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
mapper.setSerializationInclusion(Include.NON_NULL);
mapper.enable(MapperFeature.REQUIRE_SETTERS_FOR_GETTERS);
Tmp tmp = mapper.readValue(jsonString, Tmp.class);
Tmp
{
@JsonProperty("provider:segmentation_id")
private int segmentation_id;
}
本文介绍了一种使用Java的Jackson库进行JSON数据解析的方法。通过禁用某些特性并设置序列化包含规则来优化ObjectMapper实例,实现了从JSON字符串中读取数据到Java对象的过程。此外,还展示了一个具体的例子,即如何将JSON字段映射到Java类的属性。
508

被折叠的 条评论
为什么被折叠?



