Skip to content

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

Closed
@jolangloys

Description

@jolangloys

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.

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions