json解析,json属性带特殊符号,ObjectMapper.ReadValue的方式

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;

}

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; }
经验分享 程序员 微信小程序 职场和发展