AnnotationIntrospector doesn't override JsonAlias
See original GitHub issueHello 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:
- Created 3 years ago
- Comments:5 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@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
).@ryangardner Excellent code spelunking!