Skip to content

Commit

Permalink
fix: do not auto-expose properties absent from @JsonIgnoreProperties (
Browse files Browse the repository at this point in the history
#2068)

Only when annotation is used on the referencing type. Properties still
exposed when annotation is on declaring class or descendant.

Signed-off-by: Michael Edgar <[email protected]>
  • Loading branch information
MikeEdgar authored Nov 13, 2024
1 parent 55275e5 commit 780153e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ public boolean configuresVisibility(AnnotationTarget reference) {
private Visibility declaringClassIgnore(String propertyName, AnnotationTarget target) {
AnnotationInstance declaringClassJIP = context.annotations().getAnnotation(TypeUtil.getDeclaringClass(target),
getNames());
return shouldIgnoreTarget(declaringClassJIP, propertyName);
return shouldIgnoreTarget(declaringClassJIP, propertyName, Visibility.EXPOSED);
}

/**
Expand Down Expand Up @@ -244,18 +244,19 @@ private Visibility nestingPropertyIgnore(AnnotationTarget nesting, String proper
return Visibility.UNSET;
}
AnnotationInstance nestedTypeJIP = context.annotations().getAnnotation(nesting, getNames());
return shouldIgnoreTarget(nestedTypeJIP, propertyName);
return shouldIgnoreTarget(nestedTypeJIP, propertyName, Visibility.UNSET);
}

private Visibility shouldIgnoreTarget(AnnotationInstance jipAnnotation, String targetName) {
private Visibility shouldIgnoreTarget(AnnotationInstance jipAnnotation, String targetName,
Visibility unlistedVisibility) {
if (jipAnnotation == null || jipAnnotation.value() == null) {
return Visibility.UNSET;
}

if (Arrays.asList(jipAnnotation.value().asStringArray()).contains(targetName)) {
return Visibility.IGNORED;
} else {
return Visibility.EXPOSED;
return unlistedVisibility;
}
}

Expand All @@ -268,7 +269,7 @@ public List<DotName> getNames() {
public Visibility getDescendantVisibility(String propertyName, List<ClassInfo> descendants) {
for (ClassInfo descendant : descendants) {
AnnotationInstance declaringClassJIP = context.annotations().getAnnotation(descendant, getNames());
Visibility visibility = shouldIgnoreTarget(declaringClassJIP, propertyName);
Visibility visibility = shouldIgnoreTarget(declaringClassJIP, propertyName, Visibility.EXPOSED);

if (visibility != Visibility.UNSET) {
return visibility;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.jboss.jandex.Index;
import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonView;

Expand Down Expand Up @@ -132,6 +133,9 @@ class Abridged {

@Schema(name = "Role")
class Role {
@JsonIgnore
protected java.util.logging.Logger logger;

@JsonView(Views.Full.class)
private UUID id;
@JsonView(Views.Ingest.class)
Expand Down

0 comments on commit 780153e

Please sign in to comment.