Skip to content
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

Enable JDK17-based record tests #153

Merged
merged 1 commit into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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