You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by js...@apache.org on 2008/02/27 10:24:28 UTC
svn commit: r631521 - in /activemq/camel/trunk/camel-core/src:
main/java/org/apache/camel/converter/ObjectConverter.java
test/java/org/apache/camel/converter/ConverterTest.java
Author: jstrachan
Date: Wed Feb 27 01:24:13 2008
New Revision: 631521
URL: http://svn.apache.org/viewvc?rev=631521&view=rev
Log:
added type converters for char[] <-> String
Modified:
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/ObjectConverter.java
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/converter/ConverterTest.java
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/ObjectConverter.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/ObjectConverter.java?rev=631521&r1=631520&r2=631521&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/ObjectConverter.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/ObjectConverter.java Wed Feb 27 01:24:13 2008
@@ -147,6 +147,21 @@
}
}
+ @Converter
+ public static byte[] toByteArray(String value) {
+ return value.getBytes();
+ }
+
+ @Converter
+ public static char[] toCharArray(String value) {
+ return value.toCharArray();
+ }
+
+ @Converter
+ public static String fromCharArray(char[] value) {
+ return new String(value);
+ }
+
/**
* Returns the converted value, or null if the value is null
*/
Modified: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/converter/ConverterTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/converter/ConverterTest.java?rev=631521&r1=631520&r2=631521&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/converter/ConverterTest.java (original)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/converter/ConverterTest.java Wed Feb 27 01:24:13 2008
@@ -63,8 +63,18 @@
assertEquals("Converted to String", "1000", text);
}
- public void testConvertStringAndBytes() throws Exception {
+ public void testConvertStringToAndFromByteArray() throws Exception {
byte[] array = converter.convertTo(byte[].class, "foo");
+ assertNotNull(array);
+
+ LOG.debug("Found array of size: " + array.length);
+
+ String text = converter.convertTo(String.class, array);
+ assertEquals("Converted to String", "foo", text);
+ }
+
+ public void testConvertStringToAndFromCharArray() throws Exception {
+ char[] array = converter.convertTo(char[].class, "foo");
assertNotNull(array);
LOG.debug("Found array of size: " + array.length);