Skip to content

Commit

Permalink
Fix #157: handle Record parameters in any order
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Jun 19, 2024
1 parent 6080fdf commit 5f2b7c3
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions jr-record-test/src/test-jdk17/java/jr/Java17RecordTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,23 @@ public void testJava14RecordSerialization() throws Exception {
assertEquals(expectedDoc, json.asString(input));
}

// [jackson-jr#148]
public void testJava14RecordDeserialization() throws Exception {
JSON json = JSON.std;
// [jackson-jr#148]: simple deserialization
public void testRecordDeserializationSimple() throws Exception {
String inputDoc = "{\"message\":\"MOO\",\"object\":{\"Foo\":\"Bar\"}}";
assertEquals(new Cow("MOO", Map.of("Foo", "Bar")),
JSON.std.beanFrom(Cow.class, inputDoc));
}

Cow expected = new Cow("MOO", Map.of("Foo", "Bar"));

Cow actual = json.beanFrom(Cow.class, inputDoc);
assertEquals(expected, actual);
// [jackson-jr#157]: deserialization should work with different ordering
public void testRecordDeserializationReordered() throws Exception {
String inputDoc = "{\"object\":{\"Foo\":\"Bar\"}, \"message\":\"MOO\"}";
assertEquals(new Cow("MOO", Map.of("Foo", "Bar")),
JSON.std.beanFrom(Cow.class, inputDoc));
}
// [jackson-jr#157]: deserialization should work with missing, as well
public void testRecordDeserializationPartial() throws Exception {
String inputDoc = "{\"message\":\"MOO\"}";
assertEquals(new Cow("MOO", null),
JSON.std.beanFrom(Cow.class, inputDoc));
}
}

0 comments on commit 5f2b7c3

Please sign in to comment.