-
Notifications
You must be signed in to change notification settings - Fork 33
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
Fix snake case deserialization #189
base: 2.19
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
import org.junit.jupiter.api.Test; | ||
|
||
import com.fasterxml.jackson.annotation.JsonAlias; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.jr.ob.JSON; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
@@ -34,6 +35,11 @@ public String getMiddle() { | |
public void setLast(String str) { last = str; } | ||
} | ||
|
||
record SnakeCaseRecord( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cannot be done here, as it requires JDK beyond 8. Any Record tests need to go in separate |
||
@JsonProperty("first_name") String firstName, | ||
@JsonProperty("last_name") String lastName | ||
) {} | ||
|
||
/* | ||
/********************************************************************** | ||
/* Test methods | ||
|
@@ -62,4 +68,20 @@ public void testSimpleAliases() throws Exception | |
assertEquals("Bob", result.middle); | ||
assertEquals("Burger", result.last); | ||
} | ||
|
||
public void testSnakeCaseRecordDeserialization() throws Exception | ||
{ | ||
final String input = a2q("{ 'first_name':'John', 'last_name':'Doe' }"); | ||
SnakeCaseRecord result; | ||
|
||
// First: without setting, nothing matches | ||
result = JSON.std.beanFrom(SnakeCaseRecord.class, input); | ||
assertNull(result.firstName()); | ||
assertNull(result.lastName()); | ||
|
||
// but with annotations it's all good... | ||
result = JSON_WITH_ANNO.beanFrom(SnakeCaseRecord.class, input); | ||
assertEquals("John", result.firstName()); | ||
assertEquals("Doe", result.lastName()); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,6 +67,14 @@ has no other dependencies, and provides additional builder-style content generat | |
<groupId>de.jjohannes</groupId> | ||
<artifactId>gradle-module-metadata-maven-plugin</artifactId> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<configuration> | ||
<source>16</source> | ||
<target>16</target> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also not acceptable. Only "jr-record-test" can rely on later JDK than 8. |
||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume this is just for testing -- Jackson 2.x is JDK 8, still.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for taking a look at this draft PR. I appreciate the time and effort you invest in this open-source project :) The code in this PR still needs some refinement. I already expected that changing the JDK version is not wishful. This is just the first draft, where I focused on getting the functionality to work and gaining a better understanding of the library's internals.
Can I ask you a question about the RecordsHelper class? I've changed the visibility from default to public to use it in the AnnotationBasedIntrosepector class. I'm not sure if this change is appropriate. What do you think?