-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
30 additions
and
22 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
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 |
---|---|---|
@@ -1,29 +1,38 @@ | ||
import java.io.IOException; | ||
import java.util.Map; | ||
|
||
import com.fasterxml.jackson.jr.ob.JSON; | ||
import com.fasterxml.jackson.jr.ob.JSON.Feature; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
import java.io.IOException; | ||
import java.util.Map; | ||
import junit.framework.TestCase; | ||
|
||
/** | ||
* This test is in test module since the JDK version to be tested is higher than other, and hence supports Records. | ||
*/ | ||
public class Java17RecordTest { | ||
|
||
@Test | ||
public void testJava14RecordSupport() throws IOException { | ||
JSON jsonParser = JSON.builder().enable(Feature.USE_FIELD_MATCHING_GETTERS).build(); | ||
var expectedString = "{\"message\":\"MOO\",\"object\":{\"Foo\":\"Bar\"}}"; | ||
Cow expectedObject = new Cow("MOO", Map.of("Foo", "Bar")); | ||
public class Java17RecordTest extends TestCase | ||
{ | ||
record Cow(String message, Map<String, String> object) { | ||
} | ||
|
||
var json = jsonParser.asString(expectedObject); | ||
Assert.assertEquals(expectedString, json); | ||
// [jackson-jr#94] | ||
public void testJava14RecordSerialization() throws Exception { | ||
//JSON json = JSON.builder().enable(Feature.USE_FIELD_MATCHING_GETTERS).build(); | ||
JSON json = JSON.std(); | ||
var expectedDoc = "{\"message\":\"MOO\",\"object\":{\"Foo\":\"Bar\"}}"; | ||
Cow input = new Cow("MOO", Map.of("Foo", "Bar")); | ||
|
||
Cow object = jsonParser.beanFrom(Cow.class, json); | ||
Assert.assertEquals(expectedObject, object); | ||
assertEquals(expectedDoc, json.asString(input); | ||
} | ||
|
||
record Cow(String message, Map<String, String> object) { | ||
// [jackson-jr#148] | ||
public void testJava14RecordDeserialization() throws Exception { | ||
//JSON json = JSON.builder().enable(Feature.USE_FIELD_MATCHING_GETTERS).build(); | ||
JSON json = JSON.std(); | ||
String inputDoc = "{\"message\":\"MOO\",\"object\":{\"Foo\":\"Bar\"}}"; | ||
|
||
Cow expected = new Cow("MOO", Map.of("Foo", "Bar")); | ||
|
||
Cow actual = json.beanFrom(Cow.class, inputDoc); | ||
assertEquals(expected, actual); | ||
} | ||
} |