Skip to content

Commit

Permalink
NIFI-5664 Support ArrayList in DataTypeUtils#toArray
Browse files Browse the repository at this point in the history
NIFI-5664 Generalize to handling List

This closes apache#3049

Signed-off-by: Mike Thomsen <mikerthomsen@gmail.com>
  • Loading branch information
Carl Gieringer authored and MikeThomsen committed Oct 12, 2018
1 parent 5aa4263 commit a6b9364
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,11 @@ public static Object[] toArray(final Object value, final String fieldName, final
return dest;
}

if (value instanceof List) {
final List<?> list = (List<?>)value;
return list.toArray();
}

throw new IllegalTypeConversionException("Cannot convert value [" + value + "] of type " + value.getClass() + " to Object Array for field " + fieldName);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.nio.charset.StandardCharsets;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -168,6 +169,18 @@ public void testConvertRecordFieldToObject() {

}

@Test
public void testToArray() {
final List<String> list = Arrays.asList("Seven", "Eleven", "Thirteen");

final Object[] array = DataTypeUtils.toArray(list, "list", null);

assertEquals(list.size(), array.length);
for (int i = 0; i < list.size(); i++) {
assertEquals(list.get(i), array[i]);
}
}

@Test
public void testStringToBytes() {
Object bytes = DataTypeUtils.convertType("Hello", RecordFieldType.ARRAY.getArrayDataType(RecordFieldType.BYTE.getDataType()),null, StandardCharsets.UTF_8);
Expand Down

0 comments on commit a6b9364

Please sign in to comment.