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 retrieving lower bound from TypeVariable in Collection attribute #580

Merged
merged 3 commits into from Aug 24, 2023

Conversation

amoscatelli
Copy link
Contributor

#579

The issue is related to TypeVariable having a GenericDeclaration different from the expected inherited one.
In the example described in the issue, the GenericDeclaration is FindRequestDTO, and that doesn't match with FindCriteriaDTO.

This is an issue for https://github.com/eclipse-ee4j/yasson/blob/master/src/main/java/org/eclipse/yasson/internal/VariableTypeInheritanceSearch.java#L98

Tell me if you need a more structured approach.

Thank you

@amoscatelli
Copy link
Contributor Author

@Verdent what do you think ?

@amoscatelli amoscatelli closed this Dec 2, 2022
@Verdent
Copy link
Member

Verdent commented Dec 2, 2022

Hi @amoscatelli ,
I am sorry, I am just completely preoccupied on other project. I will definitely check that out once I have time :-)

Thank you for your contribution!
I am sorry it took me so long to answer and so you have decided to close the PR.

@amoscatelli
Copy link
Contributor Author

amoscatelli commented Dec 2, 2022

@Verdent I closed the issue because I understood the issue is not about typevariable alone, but is about a combination of typevariable and something else.

I need to research more, then I'll update the issue I opened before and if you want I'll repone the pull request.

@amoscatelli amoscatelli reopened this Dec 3, 2022
@amoscatelli amoscatelli changed the title support retrieving bound from non inherited typevariable Support retrieving lower bound from TypeVariable in Collection attribute Dec 3, 2022
@amoscatelli
Copy link
Contributor Author

amoscatelli commented Dec 3, 2022

@Verdent hi again
I wrote a test to show you the real issue

The issue is with TypeVariable (and NOT WildcardVariable) used to define a Collection of a wrapper generic class attribute.
(I reproduced the issue with both Collection and Map to tell the truth).

To get the TypeVariable (and not the WildcardVariable) I use reflection (see the getDeclaredField in the test).

The same actually works if you use the generic to define a non collection attribute, in other words if you remove Collection from the attribute.

The same works if you don't use a wrapper class too.

In other words, these combinations work :

private Collection<T> value;
private AnotherGenericTestClass<Integer, T> value;
private T value;

This combination doesn't work :

private Collection<AnotherGenericTestClass<Integer, T>> value;

By patching Yasson internal TypeUtils I made this work, but I can't exclude there is something else wrong behind.

Please let me know.

@redmitry
Copy link

redmitry commented Aug 22, 2023

This patch made my day (after loosing another one).

I have a generic API where actual entries are not specified;

public List<Resultset<T>> getResultSets() {
    return result_sets;
}

The server may put any jsonb annotated entries, but serialization on server side fails without the patch.

D.

P.S. I have attached the unit test for my case in a hope the patch is accepted.
yasson-test-580.zip

Copy link

@redmitry redmitry left a comment

Choose a reason for hiding this comment

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

The patch definitely fixes the issue.

@Verdent Verdent merged commit f371eb5 into eclipse-ee4j:master Aug 24, 2023
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.

None yet

3 participants