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

@JsonbCreator with static factory method and generic type fails #654

Open
f-wunderlich opened this issue Nov 14, 2024 · 0 comments
Open
Labels
bug Something isn't working right

Comments

@f-wunderlich
Copy link

Might be related to #599, but the symptoms are different and the proposed workaround does not work. Take the example posted there, but with a static factory method:

public class RuleResponse<T> {
    private T result;

    @JsonbCreator
    public static <T> RuleResponse<T> of(@JsonbProperty("result") T result) {
      final RuleRespone<T> response = new RuleRespone<T>();
      response.result = result;
      return response;
    }

    public T getResult() {
        return result;
    }
}

Then,

JsonbBuilder.create().fromJson(
  expectedJson, 
  new TypeLiteral<RuleResponse<Integer>>() {
    private static final long serialVersionUID = 1L;
  }
  .getType()
);

attempts to set RuleResponse#result to a BigDecimal instead of an Integer.

This is caused by VariableTypeInheritanceSearch#searchRuntimeTypeArgument due to this block:

        if (ReflectionUtils.getRawType(runtimeType) != typeVar.getGenericDeclaration()) {
            return null;
        }

typeVar.getGenericDeclaration() returns a Method, thus that test will always fail. It is unclear why this test is there. Simply removing it should result in correct resolution.

@f-wunderlich f-wunderlich added the bug Something isn't working right label Nov 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working right
Projects
None yet
Development

No branches or pull requests

1 participant