-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Unable to map snake_case JSON to Play Form with camelCase fields (Java)
- Loading branch information
1 parent
3a78ae6
commit f36d8fd
Showing
8 changed files
with
345 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
web/play-java-forms/src/test/java/play/data/JacksonJsonGetterSetterForm.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright (C) from 2022 The Play Framework Contributors <https://github.com/playframework>, 2011-2021 Lightbend Inc. <https://www.lightbend.com> | ||
*/ | ||
|
||
package play.data; | ||
|
||
import com.fasterxml.jackson.annotation.JsonGetter; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.annotation.JsonSetter; | ||
import play.data.validation.Constraints; | ||
|
||
public class JacksonJsonGetterSetterForm { | ||
|
||
@Constraints.Required private String authorName; | ||
|
||
@Constraints.Required private String bookName; | ||
|
||
@JsonGetter("author") | ||
public String getAuthorName() { | ||
return authorName; | ||
} | ||
|
||
@JsonSetter("AUTHOR-NAME") | ||
public void setAuthorName(String authorName) { | ||
this.authorName = authorName; | ||
} | ||
|
||
@JsonProperty("book_name") | ||
public String getBookName() { | ||
return bookName; | ||
} | ||
|
||
@JsonProperty("title") | ||
public void setBookName(String bookName) { | ||
this.bookName = bookName; | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
web/play-java-forms/src/test/java/play/data/JacksonJsonNamingForm.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Copyright (C) from 2022 The Play Framework Contributors <https://github.com/playframework>, 2011-2021 Lightbend Inc. <https://www.lightbend.com> | ||
*/ | ||
|
||
package play.data; | ||
|
||
import static com.fasterxml.jackson.databind.PropertyNamingStrategies.SnakeCaseStrategy; | ||
|
||
import com.fasterxml.jackson.databind.annotation.JsonNaming; | ||
import play.data.validation.Constraints; | ||
|
||
@JsonNaming(SnakeCaseStrategy.class) | ||
public class JacksonJsonNamingForm { | ||
|
||
@Constraints.Required private String authorName; | ||
|
||
public String getAuthorName() { | ||
return authorName; | ||
} | ||
|
||
public void setAuthorName(String authorName) { | ||
this.authorName = authorName; | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
web/play-java-forms/src/test/java/play/data/JacksonJsonPropertyForm.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* Copyright (C) from 2022 The Play Framework Contributors <https://github.com/playframework>, 2011-2021 Lightbend Inc. <https://www.lightbend.com> | ||
*/ | ||
|
||
package play.data; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import play.data.validation.Constraints; | ||
|
||
public class JacksonJsonPropertyForm { | ||
|
||
@Constraints.Required | ||
@JsonProperty("AuthorName") | ||
private String authorName; | ||
|
||
public String getAuthorName() { | ||
return authorName; | ||
} | ||
|
||
public void setAuthorName(String authorName) { | ||
this.authorName = authorName; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.