Skip to content

Commit 5895931

Browse files
committed
Minor tweak to #4303 tests, add release note
1 parent 12abf28 commit 5895931

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

release-notes/VERSION-2.x

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ Not yet released
1515
does not work
1616
(reported by @jonasho)
1717
(fix contributed by Joo-Hyuk K)
18+
#4303: `ObjectReader` is not serializable if it's configured for polymorphism
19+
(reported by @asardaes)
20+
(fix contributed by Joo-Hyuk K)
21+
1822

1923
2.15.3 (12-Oct-2023)
2024

src/test/java/com/fasterxml/jackson/databind/TestJDKSerialization.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
package com.fasterxml.jackson.databind;
22

3-
import java.io.*;
43
import java.util.*;
54

65
import com.fasterxml.jackson.annotation.*;
7-
import org.junit.jupiter.api.Test;
86

97
import com.fasterxml.jackson.databind.type.TypeFactory;
108

@@ -101,7 +99,7 @@ class FooNameImpl extends FooName { }
10199
*/
102100
private final ObjectMapper MAPPER = newJsonMapper();
103101

104-
public void testConfigs() throws IOException
102+
public void testConfigs() throws Exception
105103
{
106104
byte[] base = jdkSerialize(MAPPER.getDeserializationConfig().getBaseSettings());
107105
assertNotNull(jdkDeserialize(base));
@@ -122,7 +120,7 @@ public void testConfigs() throws IOException
122120
}
123121

124122
// for [databind#899]
125-
public void testEnumHandlers() throws IOException
123+
public void testEnumHandlers() throws Exception
126124
{
127125
ObjectMapper mapper = newJsonMapper();
128126
// ensure we have serializers and/or deserializers, first
@@ -155,7 +153,7 @@ public void testEnumHandlers() throws IOException
155153
assertNotNull(result2);
156154
}
157155

158-
public void testObjectWriter() throws IOException
156+
public void testObjectWriter() throws Exception
159157
{
160158
ObjectWriter origWriter = MAPPER.writer();
161159
final String EXP_JSON = "{\"x\":2,\"y\":3}";
@@ -169,7 +167,7 @@ public void testObjectWriter() throws IOException
169167
assertEquals(EXP_JSON, writer2.writeValueAsString(p));
170168
}
171169

172-
public void testObjectReader() throws IOException
170+
public void testObjectReader() throws Exception
173171
{
174172
ObjectReader origReader = MAPPER.readerFor(MyPojo.class);
175173
String JSON = "{\"x\":1,\"y\":2}";
@@ -189,7 +187,7 @@ public void testObjectReader() throws IOException
189187
assertEquals(Integer.valueOf(2), any2.properties().get("y"));
190188
}
191189

192-
public void testObjectMapper() throws IOException
190+
public void testObjectMapper() throws Exception
193191
{
194192
final String EXP_JSON = "{\"x\":2,\"y\":3}";
195193
final MyPojo p = new MyPojo(2, 3);
@@ -236,13 +234,14 @@ public void testObjectReaderSerializationWithPolymorphism()
236234
};
237235

238236
for (Class<?> clazz : classes) {
237+
// Should be enough to ask for reader for polymorphic type
238+
// (no need to actually serialize/deserialize)
239239
ObjectReader reader = newJsonMapper()
240240
.readerFor(clazz);
241241

242-
ByteArrayOutputStream baos = new ByteArrayOutputStream();
243-
ObjectOutputStream oos = new ObjectOutputStream(baos);
244-
oos.writeObject(reader); // This line should throw NotSerializableException
245-
oos.close();
242+
byte[] bytes = jdkSerialize(reader);
243+
ObjectReader result = jdkDeserialize(bytes);
244+
assertNotNull(result);
246245
}
247246
}
248247
}

0 commit comments

Comments
 (0)