Skip to content

Ensure correct ordering of delegates regardless of user input #3956

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

Closed
wants to merge 5 commits into from

Conversation

MaheshAravindV
Copy link
Contributor

Ensure correct ordering of delegates regardless of user input.
Fixes: #3953

When there are multiple serializers available for that a type can
be assigned to, the most specific one should be used

Signed-off-by: Mahesh Aravind V <[email protected]>
Signed-off-by: Mahesh Aravind V <[email protected]>
Signed-off-by: Mahesh Aravind V <[email protected]>
Signed-off-by: Mahesh Aravind V <[email protected]>
@MaheshAravindV MaheshAravindV changed the title 3953 Ensure correct ordering of delegates regardless of user input Jun 16, 2025
* is assignable from the target object's class. When multiple matches are possible,
* the most specific matching class is selected — that is, the closest match in the
* class hierarchy.
*
Copy link
Member

Choose a reason for hiding this comment

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

No blank lines in method JavaDocs, please.
You can use spring-framework.xml IntelliJ IDEA editor config from the project to realign with our code style.

Copy link
Member

Choose a reason for hiding this comment

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

Have not been addressed yet

* @author Mahesh Aravind V
*
*/
class DelegatingByTypeSerializerTests {
Copy link
Member

Choose a reason for hiding this comment

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

Why do you create a new test class if we have one on the matter already: DelegatingSerializationTests?
Please, consider to add your test over there.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is a class DelegatingSerializer and the DelegatingSerializationTests is for tests of that class I assume.

Copy link
Member

Choose a reason for hiding this comment

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

It is true, but I see tests for DelegatingByTypeSerializer over there, so I would like to have your new one over there as well.
And what is the reason of @Nested?
Cannot we really have it as a top-level test method and have the code flow as simple as it could be?

Copy link
Contributor

Choose a reason for hiding this comment

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

@MaheshAravindV It's better to have all the tests in DelegatingSerializationTests. Could you move it there?

* is assignable from the target object's class. When multiple matches are possible,
* the most specific matching class is selected — that is, the closest match in the
* class hierarchy.
*
Copy link
Member

Choose a reason for hiding this comment

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

Have not been addressed yet

* @author Mahesh Aravind V
*
*/
class DelegatingByTypeSerializerTests {
Copy link
Member

Choose a reason for hiding this comment

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

It is true, but I see tests for DelegatingByTypeSerializer over there, so I would like to have your new one over there as well.
And what is the reason of @Nested?
Cannot we really have it as a top-level test method and have the code flow as simple as it could be?

return -1;
}

return 0;
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if more robust algorithm would be like this:

public class ClassHierarchyComparator implements Comparator<Class<?>> {

    @Override
    public int compare(Class<?> class1, Class<?> class2) {
        if (class1 == class2) {
            return 0; // Classes are the same
        }
        if (class1.isAssignableFrom(class2)) {
            return -1; // class1 is a superclass or superinterface of class2, so class1 should come first
        }
        if (class2.isAssignableFrom(class1)) {
            return 1; // class2 is a superclass or superinterface of class1, so class2 should come first
        }
        return class1.getName().compareTo(class2.getName()); // If no inheritance relation, compare by name
    }
}

Copy link
Member

@artembilan artembilan left a comment

Choose a reason for hiding this comment

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

Can you, please, update PR ASAP?
We have release to do and would like include this a well.

Otherwise lets us know and we address the rest of review ourselves on merge.

Thanks

@artembilan
Copy link
Member

Has been merged as df5860d
With subsequent clean up and refinements: 797b96e

@MaheshAravindV ,

thank you for contribution; looking forward for more!

@artembilan artembilan closed this Jun 16, 2025
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.

Random behavior in DelegatingByTypeSerializer based on type of delegates map
3 participants