From f00a0076d6ec3765a71a8186e9884cc6bb5e140f Mon Sep 17 00:00:00 2001 From: Michael Minella Date: Tue, 9 Oct 2012 10:12:27 -0500 Subject: [PATCH] BATCH-1684: Forcing the use of ISO-8859-1 encoding for persistence --- .../batch/core/repository/dao/JdbcExecutionContextDao.java | 7 +++++-- .../dao/DefaultExecutionContextSerializerTests.java | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcExecutionContextDao.java b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcExecutionContextDao.java index 28785bb8e..90e555fa0 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcExecutionContextDao.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcExecutionContextDao.java @@ -224,14 +224,17 @@ public class JdbcExecutionContextDao extends AbstractJdbcBatchMetadataDao implem } ByteArrayOutputStream out = new ByteArrayOutputStream(); + String results = ""; + try { serializer.serialize(m, out); + results = new String(out.toByteArray(), "ISO-8859-1"); } catch (IOException ioe) { throw new IllegalArgumentException("Could not serialize the execution context", ioe); } - return new String(out.toByteArray()); + return results; } @SuppressWarnings("unchecked") @@ -242,10 +245,10 @@ public class JdbcExecutionContextDao extends AbstractJdbcBatchMetadataDao implem if (serializedContext == null) { serializedContext = rs.getString("SHORT_CONTEXT"); } - ByteArrayInputStream in = new ByteArrayInputStream(serializedContext.getBytes()); Map map; try { + ByteArrayInputStream in = new ByteArrayInputStream(serializedContext.getBytes("ISO-8859-1")); map = (Map) serializer.deserialize(in); } catch (IOException ioe) { diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/DefaultExecutionContextSerializerTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/DefaultExecutionContextSerializerTests.java index 404727750..9973f22df 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/DefaultExecutionContextSerializerTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/DefaultExecutionContextSerializerTests.java @@ -86,9 +86,9 @@ public class DefaultExecutionContextSerializerTests { ByteArrayOutputStream out = new ByteArrayOutputStream(); serializer.serialize(m1, out); - String s = new String(out.toByteArray()); + String s = new String(out.toByteArray(), "ISO-8859-1"); - InputStream in = new ByteArrayInputStream(s.getBytes()); + InputStream in = new ByteArrayInputStream(s.getBytes("ISO-8859-1")); Map m2 = (Map) serializer.deserialize(in); return m2; }