diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/Jackson2ExecutionContextStringSerializer.java b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/Jackson2ExecutionContextStringSerializer.java index 3dddc34d6..c360ac277 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/Jackson2ExecutionContextStringSerializer.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/Jackson2ExecutionContextStringSerializer.java @@ -1,5 +1,5 @@ /* - * Copyright 2008-2020 the original author or authors. + * Copyright 2008-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/Jackson2ExecutionContextStringSerializerTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/Jackson2ExecutionContextStringSerializerTests.java index 9122b5455..06ad612f5 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/Jackson2ExecutionContextStringSerializerTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/Jackson2ExecutionContextStringSerializerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2008-2020 the original author or authors. + * Copyright 2008-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -167,20 +167,22 @@ public class Jackson2ExecutionContextStringSerializerTests extends AbstractExecu @Test public void arrayAsListSerializationTest() throws IOException { - - Jackson2ExecutionContextStringSerializer j = new Jackson2ExecutionContextStringSerializer(); + //given + List list = Arrays.asList("foo", "bar"); + String key = "Arrays.asList"; + Jackson2ExecutionContextStringSerializer serializer = new Jackson2ExecutionContextStringSerializer(); Map context = new HashMap<>(1); - context.put("Arrays.asList", Arrays.asList("foo", "bar")); + context.put(key, list); - ByteArrayOutputStream os = new ByteArrayOutputStream(); - j.serialize(context, os); + // when + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + serializer.serialize(context, outputStream); + InputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray()); + Map deserializedContext = serializer.deserialize(inputStream); - InputStream in = new ByteArrayInputStream(os.toByteArray()); - - context = j.deserialize(in); - - String[] expectedValue = { "foo", "bar" }; - List deserializedValue = (List) context.get("Arrays.asList"); - Assert.assertArrayEquals(expectedValue, deserializedValue.toArray(new String[0])); + // then + Object deserializedValue = deserializedContext.get(key); + Assert.assertTrue(List.class.isAssignableFrom(deserializedValue.getClass())); + Assert.assertTrue(((List)deserializedValue).containsAll(list)); } }