diff --git a/release-notes/VERSION-2.x b/release-notes/VERSION-2.x index 519b8ea9c2..2688b5331f 100644 --- a/release-notes/VERSION-2.x +++ b/release-notes/VERSION-2.x @@ -15,6 +15,10 @@ Not yet released does not work (reported by @jonasho) (fix contributed by Joo-Hyuk K) +#4303: `ObjectReader` is not serializable if it's configured for polymorphism + (reported by @asardaes) + (fix contributed by Joo-Hyuk K) + 2.15.3 (12-Oct-2023) diff --git a/src/test/java/com/fasterxml/jackson/databind/TestJDKSerialization.java b/src/test/java/com/fasterxml/jackson/databind/TestJDKSerialization.java index 4da8daefc3..f9e737666f 100644 --- a/src/test/java/com/fasterxml/jackson/databind/TestJDKSerialization.java +++ b/src/test/java/com/fasterxml/jackson/databind/TestJDKSerialization.java @@ -1,10 +1,8 @@ package com.fasterxml.jackson.databind; -import java.io.*; import java.util.*; import com.fasterxml.jackson.annotation.*; -import org.junit.jupiter.api.Test; import com.fasterxml.jackson.databind.type.TypeFactory; @@ -101,7 +99,7 @@ class FooNameImpl extends FooName { } */ private final ObjectMapper MAPPER = newJsonMapper(); - public void testConfigs() throws IOException + public void testConfigs() throws Exception { byte[] base = jdkSerialize(MAPPER.getDeserializationConfig().getBaseSettings()); assertNotNull(jdkDeserialize(base)); @@ -122,7 +120,7 @@ public void testConfigs() throws IOException } // for [databind#899] - public void testEnumHandlers() throws IOException + public void testEnumHandlers() throws Exception { ObjectMapper mapper = newJsonMapper(); // ensure we have serializers and/or deserializers, first @@ -155,7 +153,7 @@ public void testEnumHandlers() throws IOException assertNotNull(result2); } - public void testObjectWriter() throws IOException + public void testObjectWriter() throws Exception { ObjectWriter origWriter = MAPPER.writer(); final String EXP_JSON = "{\"x\":2,\"y\":3}"; @@ -169,7 +167,7 @@ public void testObjectWriter() throws IOException assertEquals(EXP_JSON, writer2.writeValueAsString(p)); } - public void testObjectReader() throws IOException + public void testObjectReader() throws Exception { ObjectReader origReader = MAPPER.readerFor(MyPojo.class); String JSON = "{\"x\":1,\"y\":2}"; @@ -189,7 +187,7 @@ public void testObjectReader() throws IOException assertEquals(Integer.valueOf(2), any2.properties().get("y")); } - public void testObjectMapper() throws IOException + public void testObjectMapper() throws Exception { final String EXP_JSON = "{\"x\":2,\"y\":3}"; final MyPojo p = new MyPojo(2, 3); @@ -236,13 +234,14 @@ public void testObjectReaderSerializationWithPolymorphism() }; for (Class clazz : classes) { + // Should be enough to ask for reader for polymorphic type + // (no need to actually serialize/deserialize) ObjectReader reader = newJsonMapper() .readerFor(clazz); - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - ObjectOutputStream oos = new ObjectOutputStream(baos); - oos.writeObject(reader); // This line should throw NotSerializableException - oos.close(); + byte[] bytes = jdkSerialize(reader); + ObjectReader result = jdkDeserialize(bytes); + assertNotNull(result); } } }