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

JacksonJsonNodeJsonProvider throws class cast exceptions #1369

Open
ahaverdings-deloitte opened this issue Oct 20, 2022 · 9 comments
Open

JacksonJsonNodeJsonProvider throws class cast exceptions #1369

ahaverdings-deloitte opened this issue Oct 20, 2022 · 9 comments

Comments

@ahaverdings-deloitte
Copy link

.jsonProvider(new JacksonJsonNodeJsonProvider())

This JacksonJsonNodeJsonProvider throws class cast exceptions:
class com.fasterxml.jackson.databind.node.ArrayNode cannot be cast to class java.util.List (com.fasterxml.jackson.databind.node.ArrayNode is in unnamed module of loader 'app'; java.util.List is in module java.base of loader 'bootstrap')

Resulting that the body is never transformed when there is one rule applied that handels arrays. Once the exception is throw the original body is returned (and this line also hides the exception pretty well...)

log.trace("The body could not be filtered, the following exception {} has been thrown", e.getClass());
return body;

Issue is that the expected type of (T) would be List but JacksonJsonNodeJsonProvider on createArray() is returning an ArrayNode which is not castable to List.

A solution would be to use JacksonJsonProvider instead of JacksonJsonNodeJsonProvider

@whiskeysierra
Copy link
Collaborator

Where is this cast to a List happening?

@whiskeysierra
Copy link
Collaborator

Sounds like a bug in json-path then. Maybe there was a change in Jackson which caused this incompatibility?

@stefan-g
Copy link

stefan-g commented Jan 2, 2023

I got the same error in the logs. The class cast exception does also occurs when trying to delete a node that does not exists.

The following test shows an error:

void test(){
BodyFilter filter = JsonPathBodyFilters.jsonPath("$.invalid").delete();
System.out.println(filter.filter("application/json","{"key_1":"value 1","key_2":"value 2"}"));
}

@teggr
Copy link

teggr commented Feb 27, 2023

I have run into this issue as well. There is a bug report on the json-path project json-path/JsonPath#678 that looks to be related.

@teggr
Copy link

teggr commented Feb 28, 2023

I've tried copying the JsonPathBodyFilters to a new class and changing the implementation to the JacksonJsonProvider as @ahaverdings-deloitte mentions above.
This does resolve the issue of the ClassCastException but I'm not 100% sure what the impact of making that change is

@teggr
Copy link

teggr commented Feb 28, 2023

In the meantime, as a workaround I've used the JsonBodyFilters instead of the path:

JsonBodyFilters.replaceJsonStringProperty(Set.of("fieldName"), CONTENT_REPLACEMENT_TEXT);

@adamnation
Copy link

Also this log can be supressed by adding this to your logback.xml for now:

    <!-- quiet down the logging for logbook json filters -->
    <logger name="org.zalando.logbook.json.JsonPathBodyFilters" level="INFO"/>

@kasmarian kasmarian self-assigned this Sep 18, 2023
Copy link
Contributor

In order to prioritize the support for Logbook, we would like to check whether the old issues are still relevant.
This issue has not been updated for over six months.

  • Please check if it is still relevant in latest version of the Logbook.
  • If so, please add a descriptive comment to keep the issue open.
  • Otherwise, the issue will automatically be closed after a week.

@github-actions github-actions bot added the stale label Mar 18, 2024
@kasmarian kasmarian removed the stale label Mar 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants