Unable to map snake_case JSON to Play Form with camelCase fields (Java) #12017
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Pull Request Checklist
Helpful things
Fixes
Fixes #11171
Purpose
What does this PR do?
It maps the form data from a generic
JsonNode
to the form's backing type. After mapping, the data is converted back to a genericJsonNode
. This time annotations are ignored.When the
errorsAsJson
method is called, it maps internal form field names (authorName
) back to the corresponding JSON data field names (author_name
).It fixes
testLangErrorsAsJson()
inHttpFormsTest
by changingfoo
toamount
. This was needed because theMoney
form doesn't have a field calledfoo
.It fixes the
fail with exception when the json payload is bigger than default maxBufferSize
test scenario inDynamicFormSpec
. ATextNode
can't be mapped to aDynamicForm.Dynamic
while aJsonObject
can.Background Context
Why did you take this approach?
The form data is converted to the form's backing type, so that Jackson naming annotations like
@JsonNaming
,@JsonProperty
,@JsonSetter
are applied to the form fields (e.g. fromauthor_name
toauthorName
). When mapping back, annotations are ignored to preserve the field names obtained from the previous mapping step (authorName
staysauthorName
).I needed to fix the tests, because JSON form binding has become stricter due to the mapping from generic
JsonNode
to the form's backing type.References
Are there any relevant issues / PRs / mailing lists discussions?