question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

AnnotationIntrospector doesn't override JsonAlias

See original GitHub issue

Hello all!

Thank you for the awesome work. While using Jackson within my own framework, I came across some potentially weird behaviour.

Use Case: I want to dynamically add Json Aliases to fields marked with a certain annotation(that I don’t control)

I would expect that overriding like this should do the trick, but it doesn’t. If I add the JsonAlias annotation myself, it works.

@Override
    public List<PropertyName> findPropertyAliases(Annotated ann) {
        if (isId(ann)) {
            return List.of(new PropertyName("_id"), new PropertyName("id"));
        }
        return super.findPropertyAliases(ann);
    }
    
    

    private boolean isId(Annotated annotated) {

        return annotated.hasAnnotation(Id.class)
                || annotated.hasAnnotation(javax.persistence.Id.class)
                || annotated.hasAnnotation(Identifier.class)
                || annotated.getName().equals("id");

    }

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
cowtowncodercommented, Apr 24, 2020

@RyanSusana that is weird. Thank you for investigating this part. Code looks legit. About the only thing better than this would be unit test based on pieces above – I’ll add this to my todo list to hopefully check out soon (depending on other tasks). Or, if you have time and interest, you can create one and attach too: just needs to have no additional dependencies so can reduce to minimal reproduction (just check for id named property for example, pass in “_id”).

One other thing: make sure to test with latest Jackson version (2.10.3) if not using that – there is at least one fix (#2378 in 2.10.0) since addition of @JsonAlias).

0reactions
cowtowncodercommented, Apr 24, 2020

@ryangardner Excellent code spelunking!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Jackson Deserialization: @JsonAlias doesn't work
I try to fill up an Java Object with a Json String, which can come with different kinds of variable names for the...
Read more >
FasterXML/jackson-databind - Gitter
Hi folks, a very high level question: I'm looking to use a Mixin to override classes which contain methods annotated with "@JsonGetter". I'd...
Read more >
Security update for jackson-databind, jackson-dataformats ...
configOverride (Boolean.class) works for both primitives and boxed boolean values + Dont track unknown props in buffer if 'ignoreAllUnknown' ...
Read more >
SUSE alert SUSE-SU-2022:1678-1 (jackson-databind ...
configOverride (Boolean.class) works for both primitives and boxed boolean values + Dont track unknown props in buffer if 'ignoreAllUnknown' ...
Read more >
com.fasterxml.jackson.databind.introspect ...
public class JacksonAnnotationIntrospector extends AnnotationIntrospector ... @Override public List findPropertyAliases(Annotated m) { JsonAlias ann ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found