-
Notifications
You must be signed in to change notification settings - Fork 736
Field beneath an array that is sometimes null cannot have a type other than varies #398
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
Comments
#365 appears to be related. Two questions:
|
Example response below which causes problem
|
Thanks. Just to be sure that we're looking at exactly the same thing, could you please put together a test that reproduces the behaviour you've described? One of the existing tests in |
Thanks for reporting this, @nakulcg. The problem should now be fixed in the latest 1.2.x and 2.0 snapshots. By default, the type will still be resolved as |
Please note that the problem with the field not having to be marked as optional still exists. That will be tackled in #402 and I hope to include that fix in 1.2.2 as well. |
@wilkinsona thanks, I usually look up here https://mvnrepository.com/artifact/org.springframework.restdocs/spring-restdocs-core, is the latest build update there? Because the last update looks like may 12th |
1.2.2 hasn't be released yet. You can using 1.2.2.BUILD-SNAPSHOT from https://repo.spring.io/snapshot in the meantime. |
This doesn't work as intended when the array contains null and then non-null values. |
Uh oh!
There was an error while loading. Please reload this page.
In a response containing an array, certain fields could be sometimes null and sometimes not. Currently JsonFieldTypeResolver marks them as Varies. This forces me to document the fields as Varies. Which IMO doesnt add any value to the docs. This leads to following error.
org.springframework.restdocs.payload.FieldTypesDoNotMatchException: The documented type of the field '[].obj' is Array but the actual type is Varies
Would it wise to make an exception for null?
here is an example patch
I could use
@JsonInclude(JsonInclude.Include.NON_NULL)
to prevent null fields in REST response but I'd like to avoid that and use null and have consistent REST response with all fields.The text was updated successfully, but these errors were encountered: