-
Notifications
You must be signed in to change notification settings - Fork 38.4k
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
Wrong error message for type mismatch in jsonPath().value() #25480
Comments
If the expected and actual types don't match by type, it should be calling this instead then so something doesn't make sense. Do you have a stacktrace? |
Extremely sorry for the confusion here. Indeed it executes the code which you referenced, Wanted to check if the error can be more specific then 'No value found at path'.
|
Indeed, that is misleading and in fact incorrect (i.e., a minor bug). At this point in the code path, we know that a value exists. So, in a local spike, I have a similar test now failing with a message similar to the following instead.
How does that sound? |
This has been fixed in 482adb9 for inclusion in 5.2.9 and 5.3 M2. Feel free to try it out in the upcoming snapshots. |
Thank you. |
Prior to this commit, if a value existed at the specified JSON path but had an incompatible type, the AssertionError thrown contained a message stating that the value did not exist (i.e., "No Value at JSON Path"), which was not only misleading but also technically incorrect. This commit fixes the error message for such use cases. For example, the AssertionError thrown in such use cases now resembles the following. At JSON path "$.name", value <Lisa> of type <java.lang.String> cannot be converted to type <byte[]> Closes spring-projectsgh-25480
spring-framework/spring-test/src/main/java/org/springframework/test/util/JsonPathExpectationsHelper.java
Line 295 in 87c5b5a
This is the code I was running
.andExpect(jsonPath("$.myRootObject.content").value(myObject.getContent()))
In json path the returned value has the datatype
String
. Somehow I wrongly putbyte[]
in the expected.myObject.getContent()
returnsbyte[]
. So I was trying to compareString
withbyte[]
. The error received should beClassCastException
.No Value at JSON Path
is misleading message.So there is value at the JSON path, its just that there is mismatch in the type. Value is present , so thrown error should give more specific issue , which is with expected and not with actual.
The text was updated successfully, but these errors were encountered: