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

Unable to map snake_case JSON to Play Form with camelCase fields (Java) #12017

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

amvanbaren
Copy link

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 generic JsonNode. 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() in HttpFormsTest by changing foo to amount. This was needed because the Money form doesn't have a field called foo.

  • It fixes the fail with exception when the json payload is bigger than default maxBufferSize test scenario in DynamicFormSpec. A TextNode can't be mapped to a DynamicForm.Dynamic while a JsonObject 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. from author_name to authorName). When mapping back, annotations are ignored to preserve the field names obtained from the previous mapping step (authorName stays authorName).

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?

@mkurz mkurz added this to the 2.9.1 / 3.0.1 milestone Oct 7, 2023
@mkurz
Copy link
Member

mkurz commented Oct 7, 2023

You need to run sbt formatCode to pass code style validation. Thanks!

Let's see if we can push this for 2.9.1 / 3.0.1.

@amvanbaren
Copy link
Author

@mkurz I've formatted the code.

@mkurz mkurz modified the milestones: 2.9.1 / 3.0.1, 2.9.2 / 3.0.2 Dec 7, 2023
@mkurz mkurz modified the milestones: 2.9.2 / 3.0.2, 2.9.3 / 3.0.3 Feb 27, 2024
@mkurz
Copy link
Member

mkurz commented Mar 14, 2024

@Mergifyio rebase

Copy link
Contributor

mergify bot commented Mar 14, 2024

rebase

✅ Branch has been successfully rebased

@mkurz mkurz modified the milestones: 3.0.3, 2.9.4 / 3.0.4 May 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unable to map snake_case JSON to Play Form with camelCase fields (Java)
2 participants