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

Specific typing information lost when executing certain java patterns #117

Open
devinrsmith opened this issue Nov 13, 2023 · 0 comments
Open
Assignees
Labels
enhancement New feature or request

Comments

@devinrsmith
Copy link
Member

Certain patterns that compile in java are not currently executable in jpy.

For example,

import jpy


_DeserializationFeature = jpy.get_type(
    "com.fasterxml.jackson.databind.DeserializationFeature"
)
_JsonMapper = jpy.get_type("com.fasterxml.jackson.databind.json.JsonMapper")
_JsonReadFeature = jpy.get_type("com.fasterxml.jackson.core.json.JsonReadFeature")

print(
    _JsonMapper.builder()
    .configure(_DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS, True)
    .enable(_JsonReadFeature.ALLOW_NON_NUMERIC_NUMBERS)
    .build()
)

fails with

Type: <class 'RuntimeError'>
Value: no matching Java method overloads found

If the code is modified as such:

print(
    _JsonMapper.builder()
    .enable(_JsonReadFeature.ALLOW_NON_NUMERIC_NUMBERS)
    .configure(_DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS, True)
    .build()
)

it works (enable comes first).

This is probably because jpy uses the base typing information from MapperBuilder as opposed to the more specific type present in the case of JsonMapper.Builder wrt com.fasterxml.jackson.databind.cfg.MapperBuilder#configure. It would be ideal if jpy knew that JsonMapper#configure returned a JsonMapper.

public class JsonMapper extends ObjectMapper
{
...
    public static class Builder extends MapperBuilder<JsonMapper, Builder> {
    ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant