我使用jsonschema2pojo-maven-plugin创建POJO,版本为0.4.30。但是当我在代码中使用这些pojo时,Jackson ObjectMapper无法识别@JsonProperty注释。下面是示例json:
{
"title": "IP Address",
"description": "Ip Address",
"type": "object",
"properties": {
"ip_address": {
"type": "string",
"minLength": 1,
"maxLength": 39,
"description": "ip address"
}
}
}我试着匹配jackson-databind版本,但不起作用。
@JsonInclude(Include.NON_NULL)
@JsonPropertyOrder({"ip_address"})
public class IpGeo {
@JsonProperty("ip_address")
@JsonPropertyDescription("ip address")
@Size(
min = 1,
max = 39
)
private String ipAddress;
@JsonProperty("ip_address")
public String getIpAddress() {
return this.ipAddress;
}
@JsonProperty("ip_address")
public void setIpAddress(String ipAddress) {
this.ipAddress = ipAddress;
}
}我希望ObjectMapper从json创建IpGeo类。它应该将ip_address映射到ipAddress。但是它给出了一个错误"ip_address字段没有被识别“。
发布于 2019-05-16 19:07:32
我在我的代码中发现了这个问题。我曾经使用过JaxbAnnotationIntrospector,它在适用于JSON映射的地方利用了JAXB注解。
https://stackoverflow.com/questions/56147357
复制相似问题