Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does my @JsonAlias not work after merging my code?

sorry but I'm still pretty new to coding/java. My webhook isn't reading aliased data. Not sure where it's breaking.

I developed a webhook in java springboot gradle using Eclipse. My original code worked just fine. I only needed to transfer pieces of certain files into the master so rather than doing a git merge I just cloned the master code and added my parts. Post merge, the code runs successfully but it's not grabbing all the info. The payload has "user_username" which I called "username" so I used an alias plus made sure everything was imported and dependencies were listed. The only issue I can think of is my jackson-annotations version says it's overriding a 2.8 version (@JsonAlias is 2.9 and up). I don't have another annotations but I do have a jackson-core v2.8 that I tried exclude on and it still didn't work.

My class variable:

import com.fasterxml.jackson.annotation.JsonAlias;
@JsonAlias({"user_username"})
private String username;

My getter:

public String getUsername() {
    return username;
}

My call:

String commitUsername = payload.getUsername();

My pom:

<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-annotations</artifactId>
    <version>2.10.0.pr1</version>
    <exclusions>
        <exclusion>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-core</artifactId>
        </exclusion>
    </exclusions>
</dependency> 

I expected my commitUsername to be "root_user" but instead I get null.

like image 606
Michael E. Avatar asked Nov 24 '25 02:11

Michael E.


1 Answers

After hours of trying to delete, move around, and override dependencies. The issue was that master was using the outdated jackson-core. The master owner caught this too and updated so I didn't have to find a solution. Thanks for the help though. One bandage repair: Just use what they used prior to annotations 2.9, @JsonProperty("user_username")

like image 93
Michael E. Avatar answered Nov 25 '25 17:11

Michael E.