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

Add support for Records in JDK 14 #766

Merged
merged 24 commits into from
Mar 18, 2021
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: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ Project license(s): 3-Clause BSD License

* You will only Submit Contributions to which You have the necessary rights. This means that if You are employed You have received the necessary permissions from Your employer to make the Contributions.

* Whatever content You Contribute will be provided under the Project License(s).
* Whatever content You Contribute will be under the copyright and license listed in LICENSE.md.
4 changes: 4 additions & 0 deletions pom-main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@

<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
Expand Down
6 changes: 5 additions & 1 deletion pom-versioned.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@

<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
Expand All @@ -39,7 +43,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.1</version>
<version>3.2.4</version>
<executions>
<execution>
<phase>package</phase>
Expand Down
95 changes: 90 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@

<pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.2.0</version>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
Expand Down Expand Up @@ -220,13 +226,46 @@
</plugins>
</build>
</profile>
<!-- Include any tests that require JDK11+ -->
<profile>
<id>jdk11ge</id>
<activation>
<jdk>[11,</jdk>
</activation>
<build>
<pluginManagement>
<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>test-jdk11</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
<!-- Include any tests that require JDK14+ -->
<profile>
<id>until-java11</id>
<id>jdk14ge</id>
<activation>
<!-- Use exclusive 11 range instead of inclusive 10, because an upper bound ",10]" is likely not to include most releases of 10,
since they will have an additional "patch" release such as _05 that is not taken into consideration in the above range.
See also http://maven.apache.org/guides/introduction/introduction-to-profiles.html#Details_on_profile_activation -->
<jdk>[1.5,11)</jdk>
<jdk>[14,</jdk>
</activation>
<build>
<plugins>
Expand All @@ -241,6 +280,52 @@
</configuration>
</plugin>
</plugins>
<pluginManagement>
<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>test-jdk11</source>
<source>test-jdk14</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<optimize>true</optimize>
<!-- Enable Java 14+ for all sources so that Intellij picks the right language level -->
<source>${java.vm.specification.version}</source>
<target>${java.vm.specification.version}</target>
<compilerArgs>
<arg>-parameters</arg>
<arg>--enable-preview</arg>
<arg>--add-exports=java.base/jdk.internal.ref=ALL-UNNAMED</arg>
<arg>--add-exports=java.base/sun.nio.ch=ALL-UNNAMED</arg>
</compilerArgs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>--enable-preview</argLine>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
</profiles>
Expand Down
16 changes: 16 additions & 0 deletions src/com/esotericsoftware/kryo/Kryo.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
import com.esotericsoftware.kryo.serializers.ImmutableCollectionsSerializers;
import com.esotericsoftware.kryo.serializers.MapSerializer;
import com.esotericsoftware.kryo.serializers.OptionalSerializers;
import com.esotericsoftware.kryo.serializers.RecordSerializer;
import com.esotericsoftware.kryo.serializers.TimeSerializers;
import com.esotericsoftware.kryo.util.DefaultClassResolver;
import com.esotericsoftware.kryo.util.DefaultGenerics;
Expand Down Expand Up @@ -229,6 +230,10 @@ public Kryo (ClassResolver classResolver, ReferenceResolver referenceResolver) {
OptionalSerializers.addDefaultSerializers(this);
TimeSerializers.addDefaultSerializers(this);
ImmutableCollectionsSerializers.addDefaultSerializers(this);
// Add RecordSerializer if JDK 14+ available
if (isClassAvailable("java.lang.Record")) {
addDefaultSerializer("java.lang.Record", RecordSerializer.class);
}
lowPriorityDefaultSerializerCount = defaultSerializers.size();

// Primitives and string. Primitive wrappers automatically use the same registration as primitives.
Expand Down Expand Up @@ -279,6 +284,17 @@ public void addDefaultSerializer (Class type, SerializerFactory serializerFactor
insertDefaultSerializer(type, serializerFactory);
}

/** Instances with the specified class name will use the specified serializer when {@link #register(Class)} or
* {@link #register(Class, int)} are called.
* @see #setDefaultSerializer(Class) */
public void addDefaultSerializer(String className, Class<? extends Serializer> serializer) {
try {
addDefaultSerializer(Class.forName(className), serializer);
} catch (ClassNotFoundException e) {
throw new KryoException("default serializer cannot be added: " + className);
}
}

/** Instances of the specified class will use the specified serializer when {@link #register(Class)} or
* {@link #register(Class, int)} are called. Serializer instances are created as needed via
* {@link ReflectionSerializerFactory#newSerializer(Kryo, Class, Class)}. By default, the following classes have a default
Expand Down
Loading