Skip to content

Commit

Permalink
Enable JDK17-based record tests (#153)
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder authored Jun 14, 2024
1 parent 602c886 commit 9a060e0
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 7 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@ target
*.iml
*.ipr
*.iws

/target
dependency-reduced-pom.xml
54 changes: 54 additions & 0 deletions jr-record-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,58 @@
</plugins>
</build>

<!-- 13-Jun-2024, tatu: To support JDK 17 tests only when built using 17 or later,
need to define Profile... copied from jackson-databind
-->
<profiles>
<profile>
<id>java17</id>
<activation>
<jdk>17</jdk>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>add-test-source</id>
<phase>generate-test-sources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>src/test-jdk17/java</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<inherited>true</inherited>
<configuration>
<!-- Enable Java 17 for all sources so that Intellij picks the right language level -->
<source>17</source>
<release>17</release>
<compilerArgs>
<arg>-parameters</arg>
</compilerArgs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>--add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED</argLine>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>

</project>
14 changes: 7 additions & 7 deletions jr-record-test/src/test-jdk17/java/jr/Java17RecordTest.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package jr;

import java.io.IOException;
import java.util.Map;

import com.fasterxml.jackson.jr.ob.JSON;
import com.fasterxml.jackson.jr.ob.JSON.Feature;

import junit.framework.TestCase;

Expand All @@ -13,13 +11,14 @@
*/
public class Java17RecordTest extends TestCase
{
record Cow(String message, Map<String, String> object) {
public record Cow(String message, Map<String, String> object) {
}

// [jackson-jr#94]
public void testJava14RecordSerialization() throws Exception {
//JSON json = JSON.builder().enable(Feature.USE_FIELD_MATCHING_GETTERS).build();
JSON json = JSON.std();
// 13-Jun-2024, tatu: why is this explicitly needed?
JSON json = JSON.builder().enable(JSON.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"));

Expand All @@ -28,8 +27,9 @@ public void testJava14RecordSerialization() throws Exception {

// [jackson-jr#148]
public void testJava14RecordDeserialization() throws Exception {
//JSON json = JSON.builder().enable(Feature.USE_FIELD_MATCHING_GETTERS).build();
JSON json = JSON.std();
// 13-Jun-2024, tatu: why is this explicitly needed?
JSON json = JSON.builder().enable(JSON.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"));
Expand Down

0 comments on commit 9a060e0

Please sign in to comment.