jackson-annotations 的兼容版本与 jackson-core-asl 1.8.5 集成

compatible version of jackson-annotations to integrate with jackson-core-asl 1.8.5

我正在使用 jackson-core-asl 1.8.5 将 java pojo 转换为 Json。现在我想创建具有不同属性名称的 json 。为此,我使用了 jackson-annotations (@Json属性) 但它没有任何效果。似乎可能存在一些版本问题。 我无法找到与 jackson-core-asl 1.8.5 兼容的正确版本的 jackson-annotations。

我无法更改 jackson-core-asl 1.8.5 的版本。请为我的问题提出一些解决方案。

  <properties>
      <jackson-lib.ver>1.8.5</jackson-lib.ver>
</properties>
   <dependency>
    <groupId>org.codehaus.jackson</groupId>
    <artifactId>jackson-core-asl</artifactId>
    <version>${jackson-lib.ver}</version>
    </dependency>

   <dependency>
   <groupId>org.codehaus.jackson</groupId>
   <artifactId>jackson-mapper-asl</artifactId>
   <version>${jackson-lib.ver}</version>
   </dependency>
     <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-annotations</artifactId>
        <version>2.5.1</version>
        </dependency>

这是预期的输出:

 "atts": {
     "parent-id": "asd",
     "country-id": "sdfsafs"        
       }

这是我的 pojo :

public class Attr {

    @JsonProperty("parent-id")
    private String parentId;

    @JsonProperty("country-id")
    private String countryId;

    public String getParentId() {
        return parentId;
    }
    public void setParentId(String parentId) {
        this.parentId = parentId;
    }
    public String getCountryId() {
        return countryId;
    }
    public void setCountryId(String countryId) {
        this.countryId = countryId;
    }

}

现在我得到:

"atts":{ "parentId": "asd", "countryId": "sdfsafs"
}

是的。您使用了错误版本的注释——Maven 组 ID 必须与您的映射器相同; org.codehaus.jackson。而不是 Jackson 2.x.

使用的 com.fasterxml.jackson.core