Skip to content

Add GraalVM reflection config for JsonPropertyAccessor #8613

Closed
@rsenden

Description

@rsenden

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions