Skip to content

JOHNZON-431: Fix detection of class level annotations#141

Open
ArneLimburg wants to merge 1 commit into
apache:masterfrom
ArneLimburg:master
Open

JOHNZON-431: Fix detection of class level annotations#141
ArneLimburg wants to merge 1 commit into
apache:masterfrom
ArneLimburg:master

Conversation

@ArneLimburg

Copy link
Copy Markdown
Contributor

No description provided.

if (metaAnnotation != null) {
return metaAnnotation;
}
return Meta.getAnnotation(param.getType(), api);

@rmannibucau rmannibucau Jun 30, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we filter api? this one is more specific for params so guess the fallback should be at higher level

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean?

Note that the test is green, as soon, as I define a setter for "InnerObject" in "OuterObject" in the test.

Currently classes, that are only used as constructor parameters (and there is i.e. no setter with that class as parameter) are completely ignored by the rest of the code.

Grabbing them at a more general location would be somewhere deep in org.apache.johnzon.mappings.Mapper (probably in createClassMapping). That refactoring would have much more impact i.e. in scanning performance.

Shall I go that path (i.e. not only scanning fields, getters and setters there, but also constructor parameters)?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My understanding of your change is that getAnnotation(parameter) does match a class annotation, this should go on getAnnotation(Type). Several annotations can't be set on types and since johnzon enables programmatic decoration this enables broken/undefined usages so I would fix the annotation read per annotation type and not in the parameter lookup method.

note that it is fine to add a getAnnotationOnParameterOrClass method to ease that but still called per api allowing it

hope it makes sense

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that the getAnnotation(parameter) is private and just used at that location where the bug is.

So do you mean, I should just rename getAnnotation(...) to getAnnotationOnParameterOrParameterType(...) ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ArneLimburg not sure what you mean, you mean it is a bug we can't read a @JsonbProperty from a type? my point was more to add a method in the spirit of org.apache.johnzon.mapper.access.Meta#getIndirectAnnotation which does "read at that location (param) else this one (type)" with meta annotation support and use it only for the annotations allowing it like JsonbTypeAdapter, JsonbDateFormat, JsonbNumberFormat and JsonbTypeDeserializer but not JsonbProperty and JohnzonConverter (they all use the same getAnnotation).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now I got your point and directly implemented it. Feel free to have a look

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants