简体   繁体   English

Jackson 注释:有些看得见,有些看不见

[英]Jackson annotations: some are seen, some don't

I am using Jackson annotations in my Java/Maven project.我在我的 Java/Maven 项目中使用 Jackson 注释。 I have multiple Jackson annotations, but the one I recently added, @JsonAlias idn't seen.我有多个 Jackson 注释,但我最近添加的@JsonAlias没有看到。 Code of the failing class:失败的 class 的代码:

...
import com.fasterxml.jackson.annotation.JsonAlias;
import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;


@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder({ "@name" })
public class MyClass{

    /** The name. */
    @JsonProperty("@name")
    @JsonAlias({ "Name", "name" })
    private String name;

    /** The additional properties. */
    @JsonIgnore
    private Map<String, Object> additionalProperties = new HashMap<>();

    // other stuff...

}

As I said, the annotation @JsonAlias can't be resolved.正如我所说,注释 @JsonAlias 无法解析。 There are many jackson-annotations, and they are imported from this path. jackson-annotations 有很多,都是从这个路径导入的。

~/.m2/repository/com/fasterxml/jackson/core/jackson-annotations/2.8.4/jackson-annotations-2.8.4.jar

My project has this jar as a dependency.我的项目将此 jar 作为依赖项。 I don't understand how it only permits some Jackson annotations and not all of them.我不明白它如何只允许一些 Jackson 注释,而不是全部。

I tried many solutions.我尝试了很多解决方案。 Maven commands, like maven clean compile or maven clean install don't succeed, even with the update flag -U , due to the same error: Maven 命令,如maven clean compilemaven clean install不成功,即使使用更新标志-U ,由于相同的错误:

cannot find symbol
[ERROR]   symbol:   class JsonAlias
[ERROR]   location: package com.fasterxml.jackson.annotation

Deleting and rebuilding the.m2 folder.jar files doesn't work.删除并重建 .m2 文件夹。jar 文件不起作用。

So, I really don't know how to get the visibility of the @JsonAlias annotation.所以,我真的不知道如何获得 @JsonAlias 注释的可见性。 Any ideas?有任何想法吗?

It happens most likely because @JsonAlias was added since v.2.9 according to Jackson's Javadoc and release notes for v.2.9这很可能是因为根据Jackson 的 Javadoc和 v.2.9 的 发行说明,自 v.2.9 以来添加了@JsonAlias

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM