Skip to content

Commit 08f8c75

Browse files
committed
Add test to serialize/deserialize records in the execution context
1 parent c4ad90b commit 08f8c75

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2021 the original author or authors.
2+
* Copyright 2012-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -151,6 +151,17 @@ public void testComplexObject() throws Exception {
151151
compareContexts(m1, m2);
152152
}
153153

154+
@Test
155+
public void testSerializeRecords() throws IOException {
156+
Map<String, Object> m1 = new HashMap<>();
157+
m1.put("foo", new Person(1, "foo"));
158+
m1.put("bar", new Person(2, "bar"));
159+
160+
Map<String, Object> m2 = serializationRoundTrip(m1);
161+
162+
compareContexts(m1, m2);
163+
}
164+
154165
@Test(expected = IllegalArgumentException.class)
155166
public void testNullSerialization() throws Exception {
156167
getSerializer().serialize(null, null);
@@ -263,4 +274,7 @@ public String toString() {
263274

264275
}
265276

277+
public static record Person(int id, String name) implements Serializable {
278+
}
279+
266280
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2008-2021 the original author or authors.
2+
* Copyright 2008-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -47,7 +47,8 @@ public class Jackson2ExecutionContextStringSerializerTests extends AbstractExecu
4747

4848
@Before
4949
public void onSetUp() throws Exception {
50-
Jackson2ExecutionContextStringSerializer serializerDeserializer = new Jackson2ExecutionContextStringSerializer();
50+
Jackson2ExecutionContextStringSerializer serializerDeserializer = new Jackson2ExecutionContextStringSerializer(
51+
AbstractExecutionContextSerializerTests.Person.class.getName());
5152

5253
serializer = serializerDeserializer;
5354
}

0 commit comments

Comments
 (0)