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

Parsing of variables with generic types to a wrong type #327

Closed
vat78 opened this issue Feb 2, 2023 · 2 comments
Closed

Parsing of variables with generic types to a wrong type #327

vat78 opened this issue Feb 2, 2023 · 2 comments

Comments

@vat78
Copy link

vat78 commented Feb 2, 2023

I've faced with an exception that surprised me.
This is an example of the worker:

    @JobWorker(type = "processTasks")
    public void processTasks(@Variable List<Long> batch) {
        var firstElement = batch.get(0);
    }

And it fails in runtime with java.lang.ClassCastException: class java.lang.Integer cannot be cast to class java.lang.Long

Input list comes as List<Integer> in runtime and can't be matched to firstElement with type Long

@berndruecker
Copy link
Contributor

This is because the data is serialized as JSON and deserialized later, and then Jackson guesses the type depending on size (see related FasterXML/jackson-databind#504).

In general, using Type references (https://javadoc.io/static/com.fasterxml.jackson.core/jackson-core/2.12.1/com/fasterxml/jackson/core/type/TypeReference.html) or probably some annotations might also help - but this would need to be buried quite deep in the Java Client, which is probably not easy to do right. But happy to take a PR :-)

Maybe List<Number> is the easiest option @vat78 ?

@jonathanlukas
Copy link
Collaborator

I would wrap the whole variable context and provide it as @VariablesAsType:

public record BatchVariables(List<Long> batch) {}

That would work

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

No branches or pull requests

3 participants