Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] isGetters of generated Java POJOs get skipped by Jackson when Optional booleans are used #375

Closed
andreas-schilling opened this issue Jun 27, 2023 · 1 comment · Fixed by #448
Labels
acknowledged Has been viewed by one of the maintainers and is ready for further work, discussion or other steps.

Comments

@andreas-schilling
Copy link
Contributor

Describe the bug
If an Aspect model contains optional booleans, the Java POJO generator builds an accessor like for regular booleans using the isGetter naming scheme:

public Optional<Boolean> isHidden() {
  return this.hidden;
}

During visibility detection Jackson however does two checks:

  • check the name matches the isGetter convention (which it does)
  • check whether the return type is boolean (not the case)

This results in the field becoming omitted from the payload.

Where
java-pojo-getter-lib.vm

Possible fixes
Multiple solutions exist to solve this issue:

  1. use the default getter naming scheme in such a case (in this example name the method getHidden)
  2. add an additional @JsonProperty annotation (simply with the same name applied) if the boolean is wrapped inside an Optional

Most likely the first option is not what most people would expect. The second option might be confusing to see when someone looks at the generated code, because at first glance it does not make sense to apply a name "override" that does not change anything in terms of property naming.

Immediate fix
As of now, the problem is most easily fixed using a Jackson mixin with a custom Jackson Module:

public abstract class MyPojoMixin {
   @JsonProperty(value = "hidden")
   abstract public Optional<Boolean> isHidden();
}

...

setMixInAnnotation( MyPojo.class, MyPojoMixin.class );
@andreas-schilling andreas-schilling added the bug Something isn't working label Jun 27, 2023
@chris-volk chris-volk added acknowledged Has been viewed by one of the maintainers and is ready for further work, discussion or other steps. and removed bug Something isn't working labels Jul 10, 2023
ysrbo added a commit to bci-oss/esmf-sdk that referenced this issue Oct 17, 2023
ysrbo added a commit to bci-oss/esmf-sdk that referenced this issue Nov 2, 2023
ysrbo added a commit to bci-oss/esmf-sdk that referenced this issue Nov 2, 2023
Copy link

github-actions bot commented Nov 8, 2023

Release v2.4.2 addresses this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
acknowledged Has been viewed by one of the maintainers and is ready for further work, discussion or other steps.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants