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
6b3d3b8
commit 081e154
Showing
8 changed files
with
335 additions
and
32 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
39 changes: 39 additions & 0 deletions
39
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,39 @@ | ||
/* | ||
* 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; | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
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,26 @@ | ||
/* | ||
* 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 com.fasterxml.jackson.databind.annotation.JsonNaming; | ||
import play.data.validation.Constraints; | ||
|
||
import static com.fasterxml.jackson.databind.PropertyNamingStrategies.SnakeCaseStrategy; | ||
|
||
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.