Skip to content

Commit 82c1b05

Browse files
committed
Add java.sql.Timestamp to trusted classes in Jackson serializer
Resolves #3855
1 parent 7838aea commit 82c1b05

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/Jackson2ExecutionContextStringSerializer.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ static class TrustedTypeIdResolver implements TypeIdResolver {
273273
"java.time.LocalDate",
274274
"java.time.LocalTime",
275275
"java.time.LocalDateTime",
276+
"java.sql.Timestamp",
276277
"java.net.URL",
277278
"java.util.TreeMap",
278279
"java.util.HashMap",

spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/Jackson2ExecutionContextStringSerializerTests.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import java.io.ByteArrayOutputStream;
2020
import java.io.IOException;
2121
import java.io.InputStream;
22+
import java.sql.Timestamp;
23+
import java.time.Instant;
2224
import java.util.Arrays;
2325
import java.util.HashMap;
2426
import java.util.List;
@@ -185,4 +187,23 @@ public void arrayAsListSerializationTest() throws IOException {
185187
Assert.assertTrue(List.class.isAssignableFrom(deserializedValue.getClass()));
186188
Assert.assertTrue(((List<String>)deserializedValue).containsAll(list));
187189
}
190+
191+
@Test
192+
public void testSqlTimestampSerialization() throws IOException {
193+
//given
194+
Jackson2ExecutionContextStringSerializer serializer = new Jackson2ExecutionContextStringSerializer();
195+
Map<String, Object> context = new HashMap<>(1);
196+
Timestamp timestamp = new Timestamp(Instant.now().toEpochMilli());
197+
context.put("timestamp", timestamp);
198+
199+
// when
200+
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
201+
serializer.serialize(context, outputStream);
202+
InputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());
203+
Map<String, Object> deserializedContext = serializer.deserialize(inputStream);
204+
205+
// then
206+
Timestamp deserializedTimestamp = (Timestamp) deserializedContext.get("timestamp");
207+
Assert.assertEquals(timestamp, deserializedTimestamp);
208+
}
188209
}

0 commit comments

Comments
 (0)