Skip to content

Commit

Permalink
Fixed conversion from byte array to String
Browse files Browse the repository at this point in the history
  • Loading branch information
lmeyer4 committed Nov 12, 2018
1 parent 0a46690 commit 1caddc6
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
Expand Up @@ -165,7 +165,7 @@ public static <T> T convertIfNecessary(Object target, Class<T> type) {
if (ByteBuffer.class.isAssignableFrom(target.getClass())) {
return (T) new String(((ByteBuffer) target).array());
} else if (byte[].class.isAssignableFrom(target.getClass())) {
return (T) Arrays.toString((byte[]) target);
return (T) new String((byte[]) target);
}
}

Expand Down
Expand Up @@ -50,7 +50,7 @@ public void testConvertIfNecessary() {
Assert.assertEquals(TypeConversionUtils.convertIfNecessary(payload, InputStream.class).getClass(), ByteArrayInputStream.class);
Assert.assertEquals(TypeConversionUtils.convertIfNecessary(payload, Source.class).getClass(), StringSource.class);
Assert.assertEquals(TypeConversionUtils.convertIfNecessary(payload, byte[].class), payload.getBytes());
Assert.assertEquals(TypeConversionUtils.convertIfNecessary(payload.getBytes(), String.class), Arrays.toString(payload.getBytes()));
Assert.assertEquals(TypeConversionUtils.convertIfNecessary(payload.getBytes(), String.class), new String(payload.getBytes()));
Assert.assertEquals(TypeConversionUtils.convertIfNecessary(ByteBuffer.wrap(payload.getBytes()), String.class), payload);
}

Expand Down

0 comments on commit 1caddc6

Please sign in to comment.