Skip to content

Implement new BeanPropertyDefinition.getAliases() method #4336

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

Merged
merged 3 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.fasterxml.jackson.databind.introspect;

import java.util.Collections;
import java.util.Iterator;
import java.util.List;

import com.fasterxml.jackson.annotation.JsonInclude;

Expand Down Expand Up @@ -284,4 +286,15 @@ public String findReferenceName() {
* @since 2.5
*/
public abstract JsonInclude.Value findInclusion();

/**
* Method for finding all aliases of the property, if any.
*
* @return {@code List} of aliases, if any; never null (empty list if no aliases found)
*
* @since 2.17
*/
public List<PropertyName> findAliases() {
Copy link
Member

Choose a reason for hiding this comment

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

Decided to implement here for backwards compatibility (in case anything else extends base type)

Copy link
Member Author

Choose a reason for hiding this comment

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

True... good catch

return Collections.emptyList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,19 @@ public JsonInclude.Value findInclusion() {
return (v == null) ? JsonInclude.Value.empty() : v;
}

// since 2.17
@Override
public List<PropertyName> findAliases() {
AnnotatedMember ann = getPrimaryMember();
if (ann != null) {
List<PropertyName> propertyNames = _annotationIntrospector.findPropertyAliases(ann);
if (propertyNames != null) {
return propertyNames;
}
}
return Collections.emptyList();
}

public JsonProperty.Access findAccess() {
return fromMemberAnnotationsExcept(new WithMember<JsonProperty.Access>() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.Collections;
import java.util.Iterator;
import java.util.List;

import com.fasterxml.jackson.annotation.JsonInclude;

Expand Down Expand Up @@ -218,6 +219,18 @@ public JsonInclude.Value findInclusion() {
return _inclusion;
}

@Override // since 2.17
public List<PropertyName> findAliases() {
AnnotatedMember ann = getPrimaryMember();
if (ann != null) {
List<PropertyName> propertyNames = _annotationIntrospector.findPropertyAliases(ann);
if (propertyNames != null) {
return propertyNames;
}
}
return Collections.emptyList();
}

/*
/**********************************************************
/* Access to accessors (fields, methods etc)
Expand Down