Skip to content

Générics constructor parameters don't apply converters #3567

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
jolangloys opened this issue Feb 22, 2021 · 6 comments
Closed

Générics constructor parameters don't apply converters #3567

jolangloys opened this issue Feb 22, 2021 · 6 comments
Assignees
Labels
in: mapping Mapping and conversion infrastructure status: feedback-provided Feedback has been provided status: on-hold We cannot start working on this issue yet type: bug A general bug

Comments

@jolangloys
Copy link

jolangloys commented Feb 22, 2021

Given a class which has a type parameter, and is not used as super class.

public final class Wrapper<V> {
   private final V value;

   public Wrapper(V value) {
      this.value = value;
   }

   // Getters, etc...
}

When used in a constructor/setter for deserialization, with a type that requires the use of a converter, the converter is not called and the value is not converter, resulting in a ClassCastException later in the code.

For example, used in correlation with an Enum (which use a converter to be mapped to a String):

@Document
public class Foo {
   private final Wrapper<FooEnum> myEnum;

   @PersistenceConstructor
   public Foo(Wrapper<FooEnum> myEnum) {
       this.myEnum = myEnum;
   }

   // Getters, etc ...

  public enum FooEnum { FOO, BAR }
}

I have reproduced this behaviour with other classes which use a converter.

This issue looks like the #2226 one, but here we're in the case were the wrapper class is not extended with a given type.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Feb 22, 2021
@christophstrobl christophstrobl self-assigned this Feb 22, 2021
@christophstrobl
Copy link
Member

thanks for reporting - we'll look into this!

@christophstrobl christophstrobl added in: mapping Mapping and conversion infrastructure type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Feb 22, 2021
@christophstrobl
Copy link
Member

Which version are you using?
Can you provide a Minimal, Reproducible Example to help us spot the issue? I might have missed something, but was not able to reproduce the issue with this test.

@christophstrobl christophstrobl added the status: waiting-for-feedback We need additional information before we can continue label Feb 23, 2021
@jolangloys
Copy link
Author

I'am using version 2.3.2.
I'll try to make an example in the latest version.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Feb 23, 2021
@jolangloys
Copy link
Author

I have made a simple example project: https://github.com/jolangloys/example-3567

Making the example made me realize that the problem only occur when the generic class extends its generic from a super class. In my example, Wrapper extends BaseWrapper.

@christophstrobl
Copy link
Member

Thanks for the feedback - good catch!

@christophstrobl
Copy link
Member

Upgraded the sample to boot-3 snapshots and verified it works as expected with the changes in data-commons linked above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: mapping Mapping and conversion infrastructure status: feedback-provided Feedback has been provided status: on-hold We cannot start working on this issue yet type: bug A general bug
Projects
None yet
Development

No branches or pull requests

3 participants