Skip to content

Add GraalVM reflection config for JsonPropertyAccessor #8613

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
rsenden opened this issue May 5, 2023 · 0 comments · Fixed by #8614
Closed

Add GraalVM reflection config for JsonPropertyAccessor #8613

rsenden opened this issue May 5, 2023 · 0 comments · Fixed by #8614

Comments

@rsenden
Copy link

rsenden commented May 5, 2023

Expected Behavior

JsonPropertyAccessor should be usable out of the box in GraalVM native images by providing proper reflection configuration.

Current Behavior

Evaluating an SpEL expression that invokes a List method like List::contains on a Jackson ArrayNode fails with the following exception message:

org.springframework.expression.spel.SpelEvaluationException: EL1004E: Method call: Method contains(java.lang.String) cannot be found on type org.springframework.integration.json.JsonPropertyAccessor$ArrayNodeAsList

Context

We have a command-line application that invokes various REST endpoints and allows users to specify SpEL expressions to filter the results. We create our SpEL EvaluationContext using the following method:

private static final EvaluationContext createSpelEvaluationContext() {
        DefaultFormattingConversionService  conversionService = new DefaultFormattingConversionService();
        conversionService.addConverter(new JsonNodeWrapperToJsonNodeConverter());
        conversionService.addConverter(new ObjectToJsonNodeConverter());
        DateTimeFormatterRegistrar dateTimeRegistrar = new DateTimeFormatterRegistrar();
        dateTimeRegistrar.setDateFormatter(DateTimeFormatter.ISO_DATE);
        dateTimeRegistrar.setDateTimeFormatter(DateTimeFormatter.ISO_OFFSET_DATE_TIME);
        dateTimeRegistrar.registerFormatters(conversionService);
        SimpleEvaluationContext context = SimpleEvaluationContext
                .forPropertyAccessors(new JsonPropertyAccessor())
                .withConversionService(conversionService)
                .withInstanceMethods()
                .build();
        return context;
    }

When a user specifies a filtering expression like someJsonArrayProperty.contains('someValue'), this works fine in the regular Java version of our CLI application, but fails in the native images.

@rsenden rsenden added status: waiting-for-triage The issue need to be evaluated and its future decided type: enhancement labels May 5, 2023
@artembilan artembilan added type: bug in: core backport 6.0.x and removed status: waiting-for-triage The issue need to be evaluated and its future decided type: enhancement labels May 5, 2023
@artembilan artembilan added this to the 6.1.0 milestone May 5, 2023
artembilan added a commit to artembilan/spring-integration that referenced this issue May 5, 2023
Fixes spring-projects#8613

If `JsonPropertyAccessor` is registered for SpEL, it would be great
to have it working in native images as well.

Since SpEL is fully based on reflection, expose
`JsonPropertyAccessor$ComparableJsonNode` and `JsonPropertyAccessor$ArrayNodeAsList`
reflection hints for their method invocations from SpEL

**Cherry-pick to `6.0.x`**
garyrussell pushed a commit that referenced this issue May 8, 2023
Fixes #8613

If `JsonPropertyAccessor` is registered for SpEL, it would be great
to have it working in native images as well.

Since SpEL is fully based on reflection, expose
`JsonPropertyAccessor$ComparableJsonNode` and `JsonPropertyAccessor$ArrayNodeAsList`
reflection hints for their method invocations from SpEL

**Cherry-pick to `6.0.x`**
garyrussell pushed a commit that referenced this issue May 8, 2023
Fixes #8613

If `JsonPropertyAccessor` is registered for SpEL, it would be great
to have it working in native images as well.

Since SpEL is fully based on reflection, expose
`JsonPropertyAccessor$ComparableJsonNode` and `JsonPropertyAccessor$ArrayNodeAsList`
reflection hints for their method invocations from SpEL

**Cherry-pick to `6.0.x`**
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants