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

Support @JsonIgnoreProperties(allowGetters,allowSetters), align with Jackson behaviour #640

Merged
merged 3 commits into from Nov 3, 2023

Conversation

dstepanov
Copy link
Contributor

@dstepanov dstepanov commented Nov 3, 2023

Fixes #581
Fixes #550

@@ -687,6 +686,16 @@ private void visitSubtype(ClassElement supertype, ClassElement subtype, VisitorC
return;
}

if (!subtype.hasAnnotation(SerdeConfig.SerIgnored.class)) {
// Replicate the Jackson behaviour of using the ignore annotation from supertype but allow to override it
AnnotationValue<SerdeConfig.SerIgnored> serIgnored = supertype.getAnnotation(SerdeConfig.SerIgnored.class);
Copy link
Member

Choose a reason for hiding this comment

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

what if it's on the supersupertype

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The annotation is not inherited

Copy link
Member

Choose a reason for hiding this comment

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

in a hierarchy of A extends B and B extends C, and C has @SerIgnored, I think this will mean that A will only get SerIgnored if B is visited before A?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, @SerIgnored is not inherited, so adding it to B shouldn't add it to A.

Copy link
Member

Choose a reason for hiding this comment

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

but youre copying it here? i dont understand what youre saying. this code copies the annotation from the supertype, but not if it's further up, even though i assume in jackson it would still be considered for such a hierarchy

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The subtypes in this code are the subtypes of the base class defined by JsonSubTypes. The logic is called one. It’s not called on every type.

Copy link
Member

@yawkat yawkat Nov 3, 2023

Choose a reason for hiding this comment

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

ohhhh i see. does that match jackson though? my guess is that with jackson, the property is considered part of the parent class because the parent class defines a getter of that name, so JsonIgnoreProperties is considered even though it's not technically @Inherited. I doubt this behavior is specific to JsonSubTypes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See https://github.com/micronaut-projects/micronaut-serialization/pull/640/files#diff-37b66da15700d594aac6c8e6eab4763e00f8dc3b0d769186e203b400a7a557b7R800

The ignore is not inherited. With subtypes it acts the same, if you put ignore again and want to ignore something from the supertype you need to repeat it.

Copy link
Member

Choose a reason for hiding this comment

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

ive pushed a pendingfeature with the setup that i mean. the test passes with jackson-databind.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ahh, looks like Jackson respects the last definition. I can take a look in the next PR

Copy link

sonarcloud bot commented Nov 3, 2023

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 11 Code Smells

91.6% 91.6% Coverage
19.0% 19.0% Duplication

idea Catch issues before they fail your Quality Gate with our IDE extension sonarlint SonarLint

@dstepanov dstepanov merged commit 0aff967 into master Nov 3, 2023
11 of 12 checks passed
@dstepanov dstepanov deleted the jsoni branch November 3, 2023 16:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants