Federico Bicciato
Federico Bicciato

Reputation: 76

Jackson annotations: some are seen, some don't

I am using Jackson annotations in my Java/Maven project. I have multiple Jackson annotations, but the one I recently added, @JsonAlias idn't seen. Code of the failing 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. There are many jackson-annotations, and they are imported from this path.

~/.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. I don't understand how it only permits some Jackson annotations and not all of them.

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:

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.

So, I really don't know how to get the visibility of the @JsonAlias annotation. Any ideas?

Upvotes: 0

Views: 1508

Answers (1)

Nowhere Man
Nowhere Man

Reputation: 19575

It happens most likely because @JsonAlias was added since v.2.9 according to Jackson's Javadoc and release notes for v.2.9

Upvotes: 1

Related Questions