opwvhk commented on a change in pull request #1355:
URL: https://github.com/apache/avro/pull/1355#discussion_r820465995
##########
File path:
lang/java/avro/src/main/java/org/apache/avro/reflect/ReflectDatumReader.java
##########
@@ -123,22 +116,37 @@ protected void addToArray(Object array, long pos, Object
e) {
* representations.
*/
protected Object readArray(Object old, Schema expected, ResolvingDecoder in)
throws IOException {
- Schema expectedType = expected.getElementType();
+ return readArray(old, null, expected, in);
+ }
+
+ private Object readArray(Object old, Type type, Schema expected,
ResolvingDecoder in) throws IOException {
+ Class<?> elementClass = null;
+ if (type instanceof Class && ((Class<?>) type).isArray()) {
+ // get array element class
+ elementClass = ((Class<?>) type).getComponentType();
+ } else if (type instanceof ParameterizedType
+ && Collection.class.isAssignableFrom((Class<?>) ((ParameterizedType)
type).getRawType())) {
+ // get collection element class
+ elementClass = (Class<?>) ((ParameterizedType)
type).getActualTypeArguments()[0];
+ }
Review comment:
Nicely done!
This logic also occurs in `readAndConvert` as well, and I think it would be
easier to understand if extracted info a method.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]