Expose ClassLoader from DefaultDeserializer

Add a public accessor for the ClassLoader configured on a
DefaultDeserializer instance so that callers no longer need to read the
private field via reflection in order to forward it to a
ConfigurableObjectInputStream subclass.

See gh-36827
Closes gh-36833

Signed-off-by: seonwoo_jung <laborlawseon@kap.kr>
This commit is contained in:
seonwoo_jung
2026-05-26 16:35:37 +02:00
committed by Sam Brannen
parent 1e843fd3ec
commit f7be796c1c
2 changed files with 22 additions and 0 deletions
@@ -59,6 +59,17 @@ public class DefaultDeserializer implements Deserializer<Object> {
}
/**
* Return the {@link ClassLoader} to use for deserialization, or {@code null}
* to use the "latest user-defined ClassLoader" of {@link ObjectInputStream}.
* @since 7.1
* @see ConfigurableObjectInputStream#ConfigurableObjectInputStream(InputStream, ClassLoader)
*/
public @Nullable ClassLoader getClassLoader() {
return this.classLoader;
}
/**
* Read from the supplied {@code InputStream} and deserialize the contents
* into an object.
@@ -78,6 +78,17 @@ class SerializerTests {
assertThat(deserializer.expectedInputStream).isNotNull();
}
@Test
void defaultDeserializerExposesNullClassLoaderByDefault() {
assertThat(new DefaultDeserializer().getClassLoader()).isNull();
}
@Test
void defaultDeserializerExposesConfiguredClassLoader() {
ClassLoader classLoader = getClass().getClassLoader();
assertThat(new DefaultDeserializer(classLoader).getClassLoader()).isSameAs(classLoader);
}
@Test
void serializationDelegateWithExplicitSerializerAndDeserializer() throws IOException {
SerializationDelegate delegate = new SerializationDelegate(new DefaultSerializer(), new DefaultDeserializer());