Skip to content

Rest Docs 2.0.0 - JsonAttribute Not Found becaus of changed JsonFieldProcessor#foundMatch() behaviour #492

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
AnnaMaus86 opened this issue Mar 16, 2018 · 2 comments
Labels
status: duplicate Duplicate of another issue

Comments

@AnnaMaus86
Copy link

Hi there,

we recently upgraded to Rest Docs 2.0.0 from 1.1.2.

The behaviour of JsonFieldProcessor#foundMatch() has changed, so that some json-attributes are marked as missing (although) present (according to 1.1.2 #foundMatch()).

The reason is that in 1.1.2 it was sufficient when the searched json-attribute (key) is present in the processingContext#getPayload() map. Just 'true' was returned then.

But in 2.0.0 the #foundMatch() method combine certain MatchTypes (in my case MatchType.ABSENT with MatchType.NON_NULL) when the searched json-attribute (key) is present in the processingContext#getPayload() map.

So the foundMatch() method finally returns the value MatchType.MIXED.
BUT JsonFieldProcessor#fieldFound() only returns true the resulting MatchType is MatchType.NON_NULL or MatchType.NULL.

It looks like a bug to me.

My Testdata:
Travesed JSON (Debug-Output):
[ {id=18},
{id=19, myArray=[ {mySearchedAttribute=someValue, formular=B} ]},
{id=20} ]

I searched for:
fieldWithPath("[].myArray[].mySearchedAttribute").

Maybe it has something to do with the fact that 'myArray' is only present in the second Array-Element (I didn't mark the fieldWithPath as optional as in my UnitTest it shall occure in the response).
But it was okay in RestDocs 1.1.2.

Any idea?

@wilkinsona
Copy link
Member

It only worked previously due to a bug that was fixed by #398. Please see #475 for some further explanation.

@wilkinsona wilkinsona added the status: duplicate Duplicate of another issue label Mar 16, 2018
@AnnaMaus86
Copy link
Author

Thanks for your "hyperspeed fast" reply.

In conclusion I marked the "fieldWithPath("[].myArray[].mySearchedAttribute")" as optional, as 'myArray' is optional in my testdata example.

We used this expression in order to say "if 'myArray' is present" when 'mySearchedAttribute' must be present. Now we need to adjust our tests.

Thanks for your help :-).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: duplicate Duplicate of another issue
Projects
None yet
Development

No branches or pull requests

2 participants