-
Notifications
You must be signed in to change notification settings - Fork 827
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
Private nested record cannot be serialized #873
Comments
I tried to reproduce it with this test in @Test
void testNestedNonPublicRecords () {
kryo.register(ClassWithNestedRecord.class);
kryo.register(ClassWithNestedRecord.B.class);
roundTrip(4, new ClassWithNestedRecord(new ClassWithNestedRecord.B("s")));
}
static class ClassWithNestedRecord {
private record B(String y) { }
private B x;
public ClassWithNestedRecord () {}
public ClassWithNestedRecord (B s) {
x = s;
}
public boolean equals (Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ClassWithNestedRecord a = (ClassWithNestedRecord)o;
return Objects.equals(x, a.x);
}
} This test passes. Please share a runnable test that fails. |
This test fails: public class KryoRecordTest {
static class A {
private record B(String y) {
}
private B x;
public A() {
x = new B("w");
}
}
@Test
void test() throws IOException {
try ( var stream = new ByteArrayOutputStream();
var output = new Output(stream)) {
ThreadLocalKryo.get().writeClassAndObject(output, new A());
}
}
} Exception:
From pom.xml: <properties>
<maven.compiler.release>17</maven.compiler.release>
...
</properties>
<dependencies>
<dependency>
<groupId>com.esotericsoftware</groupId>
<artifactId>kryo</artifactId>
<version>5.2.1</version>
</dependency>
...
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<compilerArgs>
<compilerArg>-parameters</compilerArg>
<compilerArg>--enable-preview</compilerArg>
</compilerArgs>
</configuration>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<argLine>--enable-preview</argLine>
</configuration>
</plugin>
</plugins>
</build> There is currently no |
I was able to reproduce this issue by moving the test record to a different package. #875 should solve this problem. |
Please confirm the fix against the latest SNAPSHOT build. |
The fix works. Thank you. |
@robertvazan: Thanks a lot! Please let me know if you run into any other issue with |
Describe the bug
I am getting this exception:
To Reproduce
Environment:
Additional context
There's no exception when the record is public.
The text was updated successfully, but these errors were encountered: